[Tutor] Calling a python script using subprocess

GoodPotatoes goodpotatoes at yahoo.com
Thu Apr 28 23:18:38 CEST 2011


I am trying to execute a python script using the subprocess module.  I am feeding parameters into the script, which reads them using argparse and returns a list.

The script simply returns a list when called.  When I execute my script from my prompt, I get the following:
H:\pythonscripts>installModule.pyc --mods mod1 mod2 mod3
['mod1', 'mod2', 'mod3']
# This is the result I would like
 
 
When I call the script from within another script using subprocess I get an error:
 
p = subprocess.Popen(r'installModule.py --mods mod1 mod2 mod3', executable = sys.executable, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
 
'Unknown option: --\r\n'
'usage: installModule.py [option] ... [-c cmd | -m mod | file | -] [arg] ...\r\n'
 
Is the subprocess module the best thing for me to use?  Is there a better way to call this script?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110428/8c4242c0/attachment.html>


More information about the Tutor mailing list