[python-win32] win32process.CreateProcess alternative that takes an array

Robert Olson olson@mcs.anl.gov
Mon, 07 Apr 2003 06:29:01 -0500


At 09:53 AM 4/7/2003 +0100, Moore, Paul wrote:
>Creating a command line from an argv list in such a way that a
>user program will recreate the same argv list is dependent on the
>code used by the C runtime of the program called, and hence is
>impossible in complete generality, although it's not hard for 99%
>of cases. As long as you don't care much about what happens to
>an argument like <hello\\"\'\\""" ""\ \\ '\'there> you're going
>to be OK :-)

The formula that I've stumbled onto that appears to work, even with 
arguments with embedded spaces, is this:

         ""cmdname" "arg1" "arg2" ..."

where the string passed to os.spawn or os.popen is indeed entirely wrapped 
in quotes. I think this works because the argument is passed to cmd for 
execution..

The annoying thing is that this introduces a nonportability, where for 
win32 the whole thing is quoted, but for linux it cannot be.

--bob