[Python-Dev] Re: FWD: Re: Problem w/ IDLE on Win2000

Tim Peters tim.one at comcast.net
Sat Aug 9 00:44:15 EDT 2003


[Kurt B. Kaiser, struggles to get an embedded-space spawn to work]

I think the trick is that you shouldn't quote the executable path at all.
Under the covers, MS takes the executable name as-is, passing it as the
lpApplicationName argument to the Win32 CreateProcess(), but squashes all
your *arguments* into a single string, which gets passed on as the
lpCommandLine argument to CreateProcess().

In the arguments, you should avoid the cleverness of trying to quote only
the part(s) with a space(s).  Stick a double quote on each end of each
argument, and that's it(*).

So, for example, I made a copy of a wc.exe into

    c:\Program Files\tmp\w c.exe

and then this Python works (on Win98SE(*)) to run that program on itself:

"""
raw = r'C:\Program Files\tmp\w c.exe'

import os
print os.path.exists(raw)

decorated = '"%s"' % raw
os.spawnv(os.P_NOWAIT, raw, (decorated, decorated))
"""

Here's the output:

C:\Code\python\PCbuild>python temp2.py
True
     26     203   13824 C:\Program Files\tmp\w c.exe

C:\Code\python\PCbuild>

So I expect that IDLE is getting in trouble because it's not stuffing quotes
around an *argument* to a program it's spawning.


(*) There the fun begins.  While os.system() spawns a command shell,
    I don't think spawnv() does.  Which would be a real help here.
    Win9x use command.com by default, and Windows after that use
    cmd.exe.  They have have different quoting rules, and cmd.exe
    actually has two different sets of quoting rules (triggered by
    an option to cmd.exe, and/or by a registry setting).

    Still, I haven't tried the program above on a Win2K (etc)
    system, and somebody should before you get optimistic.  In one
    of cmd.exe's quoting nightmare modes, whether double quotes
    get stripped actually depends on the content of the quoted
    string <arghghghgh>!




More information about the Python-Dev mailing list