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

Philip Jenvey pjenvey at underboss.org
Wed May 26 00:37:31 CEST 2010


On May 25, 2010, at 2:54 PM, Paul Moore wrote:

> On 25 May 2010 13:22, Eric Smith <eric at trueblade.com> wrote:
>> 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.
> 
> However, on Windows the rules used by the C runtime are a pretty good
> baseline to work to. That's what subprocess does, and it's a good
> practical solution. It's not perfect, but practicality beats purity
> and all that....

> I'd say that this is a classic case where a library encapsulating
> cross-platform differences [1] is extremely useful. If the stdlib
> contained a cross-platform shell-quoting module, I'm pretty sure it
> could replace a big chunk of adhoc application code.

I'd also like to see both uses, splitting and joining posix/windows command lines cleaned up into a separate module.

The interface to shlex can be a little daunting to deal with, with it's odd non-posix mode that isn't actually for the Windows shell. Plus it's complicated by the fact that it's also intended to be used as a generic parser.

There's already a ticket requesting the ability to parse a Windows command line: http://bugs.python.org/issue1724822

--
Philip Jenvey


More information about the stdlib-sig mailing list