
On Tue, Mar 23, 2010 at 5:21 PM, "Martin v. Löwis" <martin@v.loewis.de> wrote:
That's really cute!
Glad you like it! I wrote another version, this time using WshShell.Exec() rather than WshShell.Run(). This way everything happens in the same terminal, although from random googling it seems that Exec() may be rather racy (the fact that you can't just hook WshScriptExec.StdOut to WScript.StdOut is kind of pathetic). I've also added some argument handling: C:\>cscript bdist.js Python26\python.exe foo bar Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation. All rights reserved. hello from python arguments: foo, bar C:\> Script: 4 // 3; ''' ; if (WScript.Arguments.length < 1) { WScript.Echo("usage: " + WScript.ScriptName + " <path to python> [args for" + " python]"); WScript.Quit(); } var args = ""; for (i=1; i<WScript.Arguments.length; i++) { args = args + " " + WScript.Arguments.Item(i); } var oExec = WScript.CreateObject("WScript.Shell") .Exec(WScript.Arguments.Item(0) + " " + WScript.ScriptFullName + args); while (oExec.Status == 0) { while (!oExec.StdOut.AtEndOfStream) { WScript.StdOut.WriteLine(oExec.StdOut.ReadLine()); } while (!oExec.StdErr.AtEndOfStream) { WScript.StdErr.WriteLine(oExec.StdErr.ReadLine()); } WScript.Sleep(100); } /* ''' # start of python script from sys import argv print("hello from python") print("arguments: " + ", ".join(argv[1:])) # end of python script */