
On Mon, 22 Mar 2010 at 21:25:55, "Martin v. L?wis" <martin@v.loewis.de> wrote:
As this might be an interesting puzzle to solve, I'd like to pose it to the entire distutils-sig readership. So here is the problem again:
As a batch file, my attempt at having a batch file that is also a Python script was to write it as
rem=""" %1 %0 exit """ <python code here>
This should have been run with argv[1] being the path to the Python interpreter. As a batch file, the first line is a comment, the second line runs Python, anbd the third line terminates the script (so it doesn't consider the following lines). As a Python script, the first block is a variable assignment, followed by the regular Python script.
Now (as Installer won't run batch files) we need the same as VBScript (or, failing that, as JScript). The script would be computed at the time of MSI generation.
I couldn't get this to work as VBScript (that requires too many line continuation characters), but I think the following JScript should work. The call to WShell.Run() pops another window, so I included a time.sleep() call to make that slow enough to notice. Fortunately JScript and python both will happily ignore integer and string literals at the beginning of the file, and JScript comments look like python floor division. I ran this at the command line like so: C:\>cscript bdist.js "Python26\python.exe" Here's the script: 4 // 3; ''' ; if (WScript.Arguments.Count() < 1) WScript.Echo("usage: " + WScript.ScriptName + " <path to python>"); else WScript.CreateObject("WScript.Shell").Run(WScript.Arguments.Item(0) + " " + WScript.ScriptFullName, 1, true); /* ''' # start of python script from time import sleep print("hello from python") sleep(5) # end of python script */ HTH, Jess