[issue10197] subprocess.getoutput fails on win32
STINNER Victor
report at bugs.python.org
Thu Mar 3 16:35:15 CET 2011
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
> 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.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10197>
_______________________________________
More information about the Python-bugs-list
mailing list