[Tutor] using python to execute from Dir A in Dir B

Alan Gauld alan.gauld at btinternet.com
Fri Oct 5 10:36:46 CEST 2007


Not sure what happened to the formatting here... It should be:

---------------------
"Alan Gauld" <alan.gauld at btinternet.com> wrote

The given example for os.system is:

sts = os.system("mycmd" + " myarg")
==>
p = Popen("mycmd" + " myarg", shell=True)
sts = os.waitpid(p.pid, 0)

To which you would need to add cwd=path making it:

p = Popen("mycmd" + " myarg", shell=True, cwd=path)
sts = os.waitpid(p.pid, 0)


The other difference using Popen is that it raises an
OSError exception if the program fails to run so you
should wrap the calls in a try/except if you want to
catch that.

------------------------

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


--------------------------------------------------------------------------------


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list