tags:

views:

225

answers:

2

I wrote a post commit script in python, "c:\myfolder\myscript.py". I want to invoke it from the post-commit script. This doesn't find it:

#!/bin/sh
c:\myfolder\myscript.py

bash thinks the command c:myfoldermyscript.py - the slashes get dropped.

So, I tried forward slashes:

#!/bin/sh
c:/myfolder/myscript.py

But then it seems like bash thinks my .py file is itself a bash script, and so I get bash errors as it mistakenly tries to interpret it.

A: 

Adding the following, the path to my python interpreter, as the first line of my python script worked:

#!C:/apps/Python25/python

Are there better ways?

Corey Trager
+2  A: 

The first line of a script is called a Shebang, and the only problem with it is:

Shebangs specify absolute paths to system executables; this can cause problems on systems which have non-standard file system layouts.
Even when systems have fairly standard paths, it is quite possible for variants of the same operating system to have different locations for the desired interpreter.

The only other way would be to call python directly within your script

 #!/bin/sh
 C:/apps/Python25/python c:/myfolder/myscript.py

Either way, forward slashes are in order: this is a bash session which is used to execute Git and its hooks.
The interest of calling directly the python interpreter would be to replace it by an environment variable:

 #!/bin/sh
 $PYTHON_HOME/python $SCRIPT_FOLDER/myscript.py
VonC
What you wrote makes sense. So, the Windows mechanism of a file extension, "py", being associated with an executable, "python.exe", so that "executing" the py file invokes python.exe, that mechanism can't be hooked into from the Windows-ignorant bash sessions, right?
Corey Trager
Right, the windows file association would not work in a bash session. But '`python`' alone (or '`python.exe`') could actually work, if '`C:/apps/Python25`' is in your PATH environment variable.
VonC
@VonC - looking at your user profile, I wonder if you would mind taking a look at this question of mine and adding your 2 cents, if you think differently from what's already there:http://stackoverflow.com/questions/1484153/how-does-bug-tracker-version-control-integration-work-with-typical-git-workflows
Corey Trager
@Corey: I will, later today (or early tomorrow).
VonC
@Corey: ... and done. Not a *complete* answer, though. Just some food for your thoughts.
VonC