STINNER Victor <victor.stin...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue10197>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to