subprocess and & (ampersand)
Steven Bethard
steven.bethard at gmail.com
Wed Jan 23 00:53:20 EST 2008
I'm having trouble using the subprocess module on Windows when my
command line includes special characters like "&" (ampersand)::
>>> command = 'lynx.bat', '-dump', 'http://www.example.com/?x=1&y=2'
>>> kwargs = dict(stdin=subprocess.PIPE,
... stdout=subprocess.PIPE,
... stderr=subprocess.PIPE)
>>> proc = subprocess.Popen(command, **kwargs)
>>> proc.stderr.read()
"'y' is not recognized as an internal or external command,\r\noperable
program or batch file.\r\n"
As you can see, Windows is interpreting that "&" as separating two
commands, instead of being part of the single argument as I intend it to
be above. Is there any workaround for this? How do I get "&" treated
like a regular character using the subprocess module?
Thanks,
STeVe
More information about the Python-list
mailing list