Author vstinner
Recipients brian.curtin, eric.araujo, jldm, ned.deily, r.david.murray, vstinner
Date 2011-03-03.15:35:14
SpamBayes Score 6.89956e-07
Marked as misclassified No
Message-id <1299166515.64.0.688201707976.issue10197@psf.upfronthosting.co.za>
In-reply-to
Content
> I tried to add a shell argument (to be able to disable the shell) and
> to accept any Popen keyword, but I don't know how to implement
> shell=False if the input is a list of arguments. list2cmdline() is
> unsafe on UNIX (see #8972).

Example of function to escape a list of arguments on UNIX:

def escapeargs(*args):
   return ' '.join(pipes.quote(arg) for arg in args)

R. David Murray disagree with me to allow getoutput(list) (shell=True) because Popen(list, shell=True) behaves differently.

subprocess.Popen(['echo Hello'], shell=True) writes 'Hello', whereas subprocess.Popen(['echo', 'Hello'], shell=True) writes nothing (because echo has no argument.

I would like to do something like that: getoutput(['echo', 'Hello']) calls Popen('echo Hello', shell=True) using escapeargs() function defined above. So getoutput(list) calls shell -c "arg1 arg2", whereas Popen(list, shell=True) calls shell -c "arg1" arg2 arg3 ...

See also issue #7839 for Popen(str, shell=False) and Popen(list, shell=True) cases.
History
Date User Action Args
2011-03-03 15:35:15vstinnersetrecipients: + vstinner, ned.deily, eric.araujo, r.david.murray, brian.curtin, jldm
2011-03-03 15:35:15vstinnersetmessageid: <1299166515.64.0.688201707976.issue10197@psf.upfronthosting.co.za>
2011-03-03 15:35:15vstinnerlinkissue10197 messages
2011-03-03 15:35:14vstinnercreate