subprocess and & (ampersand)

Steven Bethard steven.bethard at
Wed Jan 23 06:53:20 CET 2008

I'm having trouble using the subprocess module on Windows when my 
command line includes special characters like "&" (ampersand)::

 >>> command = 'lynx.bat', '-dump', ''
 >>> kwargs = dict(stdin=subprocess.PIPE,
...               stdout=subprocess.PIPE,
...               stderr=subprocess.PIPE)
 >>> proc = subprocess.Popen(command, **kwargs)
"'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?



More information about the Python-list mailing list