Command prompt not shown when running Python script with subprocess on Windows

Tim Golden mail at timgolden.me.uk
Wed May 28 01:08:35 EDT 2014


On 28/05/2014 00:01, ps16thypresenceisfullnessofjoy at gmail.com wrote:

> I want users to be able to enter paths in the XML file exactly the
> way they would be entered in a Windows shortcut. Since it is possible
> to make a Windows shortcut for path-to-script.py without the
> python.exe in front of it and have it open in its own command prompt,
> I want to be able to do the same thing in my XML file, but this is
> what I cannot figure out.

Anything done through shortcuts is making use of the Windows Shell API. 
To mimic that behaviour, you could try using that; in this case, 
ShellExecute[Ex]. For simple purposes, this is exposed in Python as 
os.startfile. If you need more control, you'd have to use the API call 
directly, either via ctypes or via the pywin32 libraries under the 
win32com.shell package.

To mimic the behaviour exactly (if that is a requirement), you could 
actually create a temporary shortcut with the desired information and 
invoke it via os.startfile.

I haven't followed the thread (and I'm offline at the moment) so I'll 
wait until I've seen it before I comment on the shlex.split / \\ dance 
above. On the surface, though, I'm not sure what it's achieving. [All 
right, I didn't wait :)].

TJG



More information about the Python-list mailing list