I have a batch file that tries to run the program specified in its first line. Similar to Unix's shebang:
C:\> more foo.bat
#!C:\Python27\python.exe
%PYTHON% foo-script.py
C:\>
What I want to know is: is there a way to automatically set %PYTHON%
to C:\Python27\python.exe
which is specified in the first line of the script following the shebang (#!
)?
Background: I am trying to do this so as to explicitly specify the Python interpreter to invoke (as there are multiple Python interpreters installed on the system) in the wrapper script.
Assumption: You can assume that script already knows it's own filename (foo
) and %~dp0
is the directory of this script. How do we read the first line excluding the shebang?
Clarification: Adding C:\PythonXY to %PATH% is not a solution. The shebang line is supposed to be modified during install time (the original script is generated on the build machine only) on the user's machine .. which may have multiple Python installations of the same version. And only the shebang line is modifyable (that is how the program works).