In the same way we can execute regular Python using shebangs (or PyLauncher on windows), can we do the same with Ipython and .ipy files?
Registering IPython in Windows registry so double-click .ipy launches IPython Console. Or from linux just adding an 'i' to '/usr/bin/python' and execute.
In Windows this would be really helpful, because one of the trickest parts of "system integration" is the command line arguments. If these could be tucked into a text file on the shebang (pylauncher style), that would be fabulous.
Not sure if I fully understand your problem, but you can create a py.ini file on Windows as described in the Customized Commands section of PEP 397 of which PyLauncher is an implementation.
[commands]
ipython=C:\Anaconda\Scripts\ipython.exe -v
Changing the path to where your local IPython is installed. If you associate the .ipy file extension with the pylauncher executable ( typically C:\Windows\py.exe and you can save the py.ini file to the same path ) and use the shebang below at the top of your .py/.ipy files they should run with ipython and the options specified in the py.ini file
#! ipython
You can also associate the ipython.exe with .ipy files on Windows and it will run the .ipy files.
Related
Problem summary
I'm trying to launch a .sh script via Windows 10 Cygwin (i.e. mintty.exe > bash.exe) but neither .profile, .bash_profile, or .bashrc are loading, which I need to update PATH env variable with Cygwin's bin directory.
Background
I'm trying to launch a script finder.sh:
#!/bin/bash
find .
read
from C:\Users\Bo\Temp\. It has unix line endings and executable bit set.
I have Cygwin installed at C:\Users\Bo\AppData\Local\Programs\cygwin64\. I do not have this path in either System or User Windows' Environment Variables (and I don't want to!). My runcoms all live in this directory under /home/Bo. My .bash_profile (and ATM .bashrc) have an export PATH="/cygdrive/c/Users/Bo/AppData/Local/Programs/cygwin64/bin":${PATH} in them.
I want to launch the script from Windows Explorer. I tried using the bash.exe and mintty.exe in the cygwin64\bin\ folder via Open > Choose another app > More apps > Look for another app on this PC. In either case the mintty window displays:
FIND: Parameter format not correct
meaning the Windows' find command was used not Cygwin's. So I have my script echo $PATH and the Cygwin/bin directory is not in PATH. If I add the proper export PATH statement from above to my own script it works fine. So, now to debug the launcher and runcoms...
I've put echo ${0} statements in .profile, .bash_profile, and .bashrc, none of which trigger which I run the .sh script, they are never run. I've read SO and the mans. I've tried creating a Shortcut to both mintty.exe and bash.exe passing a variety of -l -i -e - commands to each using Properties > Shortcut > Target and they are never run. E.g. running simply [..]\mintty.exe -h always doesn't even leave the window open.
How do I get my script to run in Windows Explorer via Cygwin's mintty.exe/bash.exe, and to read from a runcom to update PATH (to find Cygwin Linux commands, vs. updating Windows Environment Variable)?
Two part fix:
A) set a Windows Environment Variable for BASH_ENV to a .bash_env under your Cygwin HOME, and export the PATH variable to include the Cygwin/bin directory from that file. I cannot find a decent reference for this in Cygwin documentation because it seems to be simply a bash thing, but this variable is what bash looks for when running non login/interactively. Best reference: Cygwin shell doesn't execute .bashrc.
And B) run the .sh with bash.exe from Cygwin/bin using Open With....
ALSO, annoying Windows bug: when you select a program to Open With... your .sh script, it will always run 1x with a CWD from your C:\Windows\System32 directory(?!) and all other times will run fine with the CWD as the directory from your .sh script.
I am following this tutorial where i have to run this command in order to start the zookeeper server.
./bin/zookeeper-server-start.sh config/zookeeper.properties
But the problem is this command is not working properly. I found that .sh file is bash file that required cygwin. I have installed it and then run command like this
C:\cygwin64\bin\bash.exe ./bin/zookeeper-server-start.sh config/zookeeper.properties
But it is showing:
I can confirm that in bin directory the file is exsits. what i am doing wrong?
Here is my directory snapshot from where i running the command:
Note: I have successfully tested bin/windows zookeeper bat file but i want to run it through .sh file as the kafka security tutorial which i am following using this.
From your screenshot, I conclude that you are using Cygwin. So, please add the cygwin tag to your question.
As you can see from the error message, the command dirname is not found by bash, so assuming that your Cygwin installation is not broken, I assume that the PATH is not set correctly; in your setup, dirname.exe should be in C:/cygwin64/bin (please verify this).
Your usage of bash.exe is a bit unusual in that you run it directly from a Windows cmd prompt. The more common way would be to use it from the 'Cygwin Terminal', which you get created a Windows-link to, when installing Cygwin, or to use another suitable Terminal program; I'm using for instance mintty for this task (also available via the Cygwin installer).
Having said this, it is possible to run bash.exe in the way you are doing it, but you then have to ensure, that at least the PATH is set up correctly. One possibility to do this, is to add C:\cygwin64\bin to your Windows PATH, but this has the drawback, that some commands have the same name in the Windows world and in Cygwin, though they serve a completely different purpose, and this will bite you sooner or later. Another problem is that at some point, you will rely on other bash specific setups besides the PATH.
A better way to accomplish your goal is IMO to ensure, that the system wide bash-initialization files are sourced by bash. If I have to run the script from a Windows cmd prompt, I would run it by
C:\cygwin64\bin\bash.exe --login YOURSCRIPT
This will read the file (in your setup) C:\cygwin64\etc\profile before running YOURSCRIPT, so you can check, that the PATH is correctly set there, by looking at this file. In a default installation, this should be the case.
After having read this file, it will try to read the file .bash_profile in your Cygwin HOME directory, so if you need additional settings for your (non-interactive) bash-scripts, create this file and put your settings there.
After installing win-bash from sourceforge.net and creating a command prompt label and setting the path, my bash recognizes some commands like "ls", "mkdir" but not "clear" or "clean"!
the label to command prompt has this in its properties:
the red arrows points to this setpath.bat, it has this:
#echo off
SET PATH=%PATH%;C:\win-bash
bash
exit
the folder win-bash has the content from win-bash downloaded file from sourceforge + setpath.bat file.
My bash recognizes ls, mkdir - creates folders, but can't "clean". What's the reason - some shell cmds recognized, and some don't?!
P.S. It does NOT recognize most commands - mkfile, lsblk, calendar(cal)
Not an expert on win-bash, but here are some clues:
other linux emulators on Windows like mingw32, GoW provide standalone executable .exe for each program, so it is easy to see which commands are implemented just by reviewing the emulator directory (the one it appends to path)
win-bash claims from documentation it is a single-file replacement for the shell, but rest of documentation is limited
if you want to clear screen 'cls' should work it is a native windows command. On internals of 'clear' see
https://superuser.com/questions/1161514/bash-on-ubuntu-on-windows-clearing-all-the-text-all-of-it
I'm using a windows 8 and have cygwin installed. However, when I navigate to the folder it's contained in, the only subfolders are usr and var, and neither contains something that looks like a terminal. How can I open a cygwin terminal?
You should use mintty executable for this. In case of a default install path it is located here: c:\cygwin\bin\mintty.exe
Cygwin installation puts a shortcut to the start menu, but perhaps this feature was broken in win8.
I checked this shortcut on my computer, and it contains this command as a "Target":
C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -
You should create a shortcut like this. Replace the given path, if your cygwin is located anywhere else. -i command line argument is not necessary. For further info check the manual page of mintty, which is located here.
You can run
c:\program files\cygwin\bin\bash.exe
inside the Windows CMD.
When you install cygwin, it normally installs a ".bat" file at the top of the directory-tree containing cygwin, which can run a command-window. For example:
#echo off
C:
chdir C:\cygwin64\bin
bash --login -i
The exact location of the cygwin tree is relevant to the script, of course, and details change occasionally. But the bash executable, starting in cygwin's bin-directory is enough to start a window.
Outside cygwin, you will not see things such as mounted directories and symbolic links. So (from the Windows file explorer) it may look incomplete.
I am trying to compile .sh file from MATLAB on Windows. When I type mcc -m filename.m it generates .exe file but I would like to run it on Ubuntu server. Is it possible to make it on Windows?
The .sh file extension is typically used for shell scripts. Check the first line of your file. If it reads !#/bin/bash or so, you are looking at a shell script which has nothing to do with matlab. Instead, you may want to install cygwin to have the usual Linux/Unix shell programming environment available on windows.