[Tutor] using variables as args
Alan Gauld
alan.gauld at freenet.co.uk
Mon May 8 22:19:40 CEST 2006
> I'm trying to start a shell script with 4 arguments
> from my python script. I'm having problems trying to
> figure out the best way to do this.
Use a format string:
cmd = "myscript %s %s %s %s"
os.system(cmd % (p1,p2,p3,p4))
OR
cmdstr = cmd % p1,p2,p3,p4
os.system(cmdstr)
The second form is easier to debug...
> to use popen3 to keep track of stdin, stdout, and err,
Ok, substitute popen3 for system().
Or better still use the subprocess module and
the Popen class.
See the OS topic in my tutor for more on the subprocess
module.
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list