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

Eric Smith eric at trueblade.com
Tue May 25 14:22:50 CEST 2010


Éric Araujo wrote:
>> In my case, I was building up a command line to pass as a single string
>> to subprocess, and needed a way to quote the args explicitly.  That's
>> why I went looking at this.
> FYI, if you need the reverse operation (string → list), look at shlex.

Keep in mind that these routines typically only work on Unix-like 
systems, where the shell has a set of well defined rules for quoting and 
parsing. On Windows, each executable is in charge of parsing its own 
parameters from a string. This is usually (but certainly not always) 
done by the C runtime startup. But different runtimes have different 
rules. Sadly, you sometimes have to know which executable you're calling 
before you can know how to escape its arguments.

-- 
Eric.


More information about the stdlib-sig mailing list