[wingide-users] Using subprocess in scripts

Wingware Support support at wingware.com
Mon Jan 1 11:09:07 MST 2007

Michael Foord wrote:
> I would like to use 'subprocess' to launch commands. The 'subprocess' 
> module isn't included in the Wing 'Python24.zip', so I can't use it. Any 
> reason why it isn't available ?

The subprocess module isn't included because Wing doesn't use in 
internally and Python24.zip only includes the python library modules 
that Wing uses.  We should probably expand what is included so that 
scripts may use other modules.

Ordinarily, I'd suggest that you use the AsyncExecuteCommandLine method 
on the wingapi Application class, but I think you want to create a new 
cmd.exe window each time you run the command (actually, you probably 
don't want to, but it's probably the easiest option to get a console 
working).  Given that, I came up with the following:

import wingapi
import os

from wingutils import spawn

def custom_execute(app=wingapi.kArgApplication):
   editor = app.GetActiveEditor()
   filename = editor.GetDocument().GetFilename()
   directory, theFile  = os.path.split(filename)
   env = app.GetProject().GetEnvironment(filename)
   cmd = env.get('COMSPEC', 'cmd.exe')
   argv = [cmd, '/c', 'run_python.bat', filename]
   spawn.win32_start_process(cmd, argv, env=env, child_pwd=directory,

It uses Wing's internal spawn module to get an api to create a new 
console.  I tried using os.spawn* functions, but couldn't determine how 
to create a console though I didn't try for very long.  Also, the 
command gets the environment from the project so that modifications in 
the project properties are picked up.  This was a flaw in using 
os.system because os.system uses Wing's internal environment, which is 
not the same as the environment specified in project properties or the 
environment that Wing is launched in.



More information about the wingide-users mailing list