subprocess and & (ampersand)

Ross Ridge rridge at caffeine.csclub.uwaterloo.ca
Wed Jan 23 10:56:58 EST 2008


Tim Golden  <mail at timgolden.me.uk> wrote:
> but this doesn't:
>
> <c:/temp/firefox.bat>
> "c:\Program Files\Mozilla Firefox\firefox.exe" "%*"
> </c:/temp/firefox.bat>
>
> <code>
> import subprocess
>
> cmd = [
> r"c:\temp\firefox.bat",
> "http://local.goodtoread.org/search?word=tim&cached=0"
> ]
> subprocess.Popen (cmd)
>
> </code>
 
Ross Ridge wrote:
> You need to use double quotes both in the .BAT file and in the string
> you pass to subprocess.Popen().

Tim Golden  <mail at timgolden.me.uk> wrote:
>... If you simply requote the second element in the cmd list
>('"http:/....."') then the internal quotes are escaped by some part of
>the mechanism and it still doesn't work.

Hmm... I guess things are much more messy than that.  CMD doesn't do
standard quote processing of it's arguments or .BAT file arguments, and
so is incompatible with how subprocess quotes args lists.  It looks like
you need use a string instead of list with subprocess.Popen and not use
quotes in the batch file.  So something like:

firefox.bat:
	"c:\Program Files\Mozilla Firefox\firefox.exe" %1

code:
	subprocess.Popen(r'c:\temp\firefox.bat "http://local.goodtoread.org/search?word=tim&cached=0"')

					Ross Ridge

-- 
 l/  //	  Ross Ridge -- The Great HTMU
[oo][oo]  rridge at csclub.uwaterloo.ca
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //	  



More information about the Python-list mailing list