[Python-Dev] Testsuite fails on Windows if a space is in the path

Jean-Paul Calderone exarkun at divmod.com
Sat Sep 16 19:38:06 CEST 2006

On Sat, 16 Sep 2006 19:22:34 +0200, "\"Martin v. Löwis\"" <martin at v.loewis.de> wrote:
>The test suite currently (2.5) has two failures on Windows
>if Python is installed into a directory with a space in it
>(such as "Program Files"). The failing tests are test_popen
>and test_cmd_line.
>The test_cmd_line failure is shallow: the test fails to properly
>quote sys.executable when passing it to os.popen. I propose to
>fix this in Python 2.5.1; see #1559413
>test_popen is more tricky. This code has always failed AFAICT,
>except that the test itself is a recent addition. The test tries
>to pass the following command to os.popen
>"c:\Program Files\python25\python.exe" -c "import sys;print sys.version"
>For some reason, os.popen invokes doesn't directly start Python as
>a new process, but install invokes
>cmd.exe /c "c:\Program Files\python25\python.exe" -c "import sys;print
>Can somebody remember what the reason is to invoke cmd.exe (or COMSPEC)
>in os.popen?

I would guess it was done to force cmd.exe-style argument parsing in the
subprocess, which is optional on Win32.

>In any case, cmd.exe fails to execute this, claiming that c:\Program
>is not a valid executable. It would run
>cmd.exe /c "c:\Program Files\python25\python.exe"
>just fine, so apparently, the problem is with argument that have
>multiple pairs of quotes. I found, through experimentation, that it
>*will* accept
>cmd.exe /c ""c:\Program Files\python25\python.exe" -c "import sys;print
>(i.e. doubling the quotes at the beginning and the end). I'm not quite
>sure what algorithm cmd.exe uses for parsing, but it appears that
>adding a pair of quotes works in all cases (at least those I could think
>of). See # 1559298

You can find the quoting/dequoting rules used by cmd.exe documented on msdn:


Interpreting them is something of a challenge (my favorite part is how the
examples imply that the final argument is automatically uppercased ;)

Here is an attempted implementation of the quoting rules:


Whether or not it is correct is probably a matter of discussion.  If you find
a more generally correct solution, I would certainly like to know about it.


More information about the Python-Dev mailing list