Re: Waiting for a subprocess to exit

2009-08-25 Thread Aahz
In article , Miles Kaufmann wrote: > >debacle[1]). Leaving shell=3DFalse makes scripts more secure and =20 >robust; besides, when I'm putting together a command and its =20 >arguments, it's as convenient to build a list (['mycmd', 'myarg']) as =20= > >it is a string (if not more so). unless

Re: Sanitising arguments to shell commands (was: Waiting for a subprocess to exit)

2009-08-21 Thread Chris Rebert
On Fri, Aug 21, 2009 at 2:08 AM, Ben Finney wrote: > How can I take a string that is intended to be part of a command line, > representing multiple arguments and the shell's own escape characters as > in the above example, and end up with a sane command argument list for > ‘subprocess.Popen’? htt

Sanitising arguments to shell commands (was: Waiting for a subprocess to exit)

2009-08-21 Thread Ben Finney
Miles Kaufmann writes: > I would recommend avoiding shell=True whenever possible. It's used in > the examples, I suspect, to ease the transition from the functions > being replaced, but all it takes is for a filename or some other input > to unexpectedly contain whitespace or a metacharacter and

Re: Waiting for a subprocess to exit

2009-08-21 Thread Ben Finney
Miles Kaufmann writes: > On Aug 20, 2009, at 10:13 PM, Ben Finney wrote: > > Why would I use ‘os.waitpid’ instead of:: > > > >process = subprocess.Popen("mycmd" + " myarg", shell=True) > >process.wait() > >status = process.returncode > > Really, you can just use: > > process = subpr

Re: Waiting for a subprocess to exit

2009-08-20 Thread Miles Kaufmann
On Aug 20, 2009, at 10:13 PM, Ben Finney wrote: The module documentation has a section on replacing ‘os.system’ , which says to use:: process = subprocess.Popen("mycmd" + " myarg", shell=True) status = os.waitpid(process.pid, 0

Waiting for a subprocess to exit

2009-08-20 Thread Ben Finney
Howdy all, I'm looking to replace some usages of ‘os.system’ with the more secure ‘subprocess.Popen’ methods. The module documentation has a section on replacing ‘os.system’ , which says to use:: process = subprocess.Popen("mycmd