[python-win32] does pipes.quote() work properly on Windows?
Tim Roberts
timr at probo.com
Mon May 24 19:04:33 CEST 2010
Bill Janssen wrote:
> I'm actually not passing file names. I'm passing argument strings,
> which may contain spaces, quotes, and other things. For instance,
>
> myprogram --title="That's the game! says Mike "Hammer" Brotsky" --file=...
>
> "myprogram" is a Python program, and expects to get the whole "--title"
> argument as a single element of sys.argv.
>
> On Unix, I use
>
> arg = "--title=%s" % pipes.quote(title)
>
> to achieve that effect. What's the equivalent on Windows? Since
> cmd.exe also supports pipelines, I'd sort of expect it to do the right
> thing on Windows, too.
>
Ah, foolish mortal.
The problem with Windows is that, as I said, there is no central
command-line parser, so there is no single set of rules. Cmd.exe does
not parse the command line. Cmd.exe does not create argc/argv. Cmd.exe
just passes the whole command line as a string. For C programs, the C
run-time library will crack that string into argc/argv. Python on
Windows has its own parser.
If you are creating a list of arguments to pass AS A LIST, then no
quoting is necessary. If you intend to mash them together into a single
string, then I'm afraid you will need to experiment.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list