views:

47

answers:

0

Hi everyone.

I seem to have discovered a problem with subprocess.Popen() on a Windows XP x64 machine. If Popen() is called with Shell=True, instead of a subprocess being created, the error

The syntax of the command is incorrect

is printed to the command prompt.

The problem was discovered when trying to use Mercurial on the command line. 'hg resolve' would crash with the above error. I've narrowed it down to a problem with Popen(), and have made a <10 line script that reproduces the issue. The problem also exists in tortoisehg in a variety of places, also due to the fact it makes use of Popen() with Shell=True.

Interestingly, if I run my test-code with Shell=False, it works fine (expected behaviour occurs). I've tested the code on a Windows x86 build, and with both Shell=True & False it works as expected. This specific machine has some customizations to the PATH, however nothing serious.

Does anybody know what could be different about this x64 machine to cause this error. The machine was already installed/setup before I came into the job, so I am unsure what has been changed. The only idea I've had so far is that there's some error occuring due to incorrect escaping of parameters (or something related), however I'm unsure where this could occur.

Just for informational purposes, I've posted one of Mercurial's calls to Popen, in case anybody spots something which might be the issue

p = subprocess.Popen(cmd, shell=True, bufsize=-1,
                     close_fds=closefds,
                     stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                     universal_newlines=newlines,
                     env=env)

Unfortunately I can't post the test-code right now (it's at work), however I will post an update the moment I can get my hands on it.

Thanks for any help.


Update, the code for the test is below...

import os
import sys
import subprocess

if 'THG_HGTK_SPAWN' in os.environ:
    print 'spawn successful'
    sys.exit(0)

os.environ['THG_HGTK_SPAWN'] = '1'

subprocess.Popen(args={'python', r'test.py'}, shell=True)

print 'spawning...'

sys.exit(0)