[stdlib-sig] quoting arguments for command-line evaluation

Bill Janssen janssen at parc.com
Mon May 24 16:46:32 CEST 2010


I'm kind of surprised to see that the subprocess module doesn't have a
documented function for calling to properly quote command-line
arguments.  Nor does it seem to do so automatically -- at least on Unix.

It *does* have an undocumented function called "list2cmdline" (refered
to in passing in the docs as a "method"), which is called automatically
if the "args" parameter to the Popen() initializer is a sequence, and
the platform is Windows, but not otherwise.  No similar quoting of args
is done for Unix.

On the other hand, the "pipes" module has another undocumented function
called "quote", which seems to perform similar quoting, but for sh.
"Pipes" is documented to work only under Unix -- which is a bit strange,
as cmd.exe supports pipes on Windows as well.

Given that Python, even 3, ships with os.system() and os.popen() and
subprocess and pipes and perhaps others that I don't know about,
exposing a quoting mechanism that appropriately quotes for either sh or
cmd.exe, depending on platform, wouldn't be a bad idea.  And perhaps
pipes should be eliminated, or re-written in terms of subprocess to be
cross-platform.

Bill


More information about the stdlib-sig mailing list