How can I get my git (msysgit on windows) post-commit script to invoke my python script as python rather than bash?

丶灬走出姿态 提交于 2019-12-03 21:07:56

问题


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.


回答1:


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



回答2:


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?



来源:https://stackoverflow.com/questions/1547005/how-can-i-get-my-git-msysgit-on-windows-post-commit-script-to-invoke-my-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!