title: Read the first line of batch file from the same batch file?
body: <p>I have a batch file that tries to run the program specified in its first line. Similar to Unix's <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)" rel="nofollow noreferrer">shebang</a>:</p>
  
  <pre><code>C:\&gt; more foo.bat
  #!C:\Python27\python.exe
  %PYTHON% foo-script.py
  C:\&gt;
  </code></pre>
  
  <p>What I want to know is: is there a way to <strong>automatically</strong> set <code>%PYTHON%</code> to <code>C:\Python27\python.exe</code> which is specified in the first line of the script following the shebang (<code>#!</code>)?</p>
  
  <p><em>Background</em>: 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.</p>
  
  <p><em>Assumption</em>: You can assume that script already knows it's own filename (<code>foo</code>) and <a href="http://weblogs.asp.net/whaggard/archive/2005/01/28/get-directory-path-of-an-executing-batch-file.aspx" rel="nofollow noreferrer"><code>%~dp0</code></a> is the directory of this script. How do we read the first line excluding the shebang?</p>
  
  <p><strong>Clarification</strong>: 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).</p>