[Tutor] subprocess.call list vs. str argument
Danny Yoo
dyoo at hashcollision.org
Tue Feb 25 21:47:48 CET 2014
See the comment about 'args' in:
http://docs.python.org/2/library/subprocess.html#frequently-used-arguments
which says:
"""args is required for all calls and should be a string, or a
sequence of program arguments. Providing a sequence of arguments is
generally preferred, as it allows the module to take care of any
required escaping and quoting of arguments (e.g. to permit spaces in
file names). If passing a single string, either shell must be True
(see below) or else the string must simply name the program to be
executed without specifying any arguments."""
This is an unfortunate pain-point in the subprocess API. Personally,
I think that having subprocess.call optionally accept a single string
is a wrong API decision because it causes so much confusion. You can
tell there's a schizophrenia in that part of the documentation: it
says something to the effect of, "If you want to use a single string,
you have to use shell=True". And a few paragraphs later, it says,
"But don't use shell=True!"
I would strongly suggest not trying to use the single string interface
to subprocess: it's too easy to get wrong.
More information about the Tutor
mailing list