2

When passing the command as a list, subprocess.Popen will automatically quote arguments that have spaces. However, if I running java with a system property that has spaces like this:

-Dwebdriver.firefox.bin="C:\Program Files (x86)\Mozilla Developer Preview\firefox.exe"

, it will give an error: 'C:\Program' is not recognized error , which I believe is because Popen would insert quotes around the entire argument if it sees a space, and escapes the rest of the double quotes. I'm not sure how I can fix this if I want to keep using the Popen command:

subprocess.Popen([
  'cmd.exe', '/C', 'C:\\Program Files\\java\\jre7\\bin\\java.exe',
  '-Dwebdriver.firefox.bin="C:\\Program Files (x86)\\Mozilla Developer Preview\\firefox.exe"',
  '-jar', 'C:\\Users\\testing\\Temp\\SeleniumServer.jar'])
chl
  • 21
  • 1

1 Answers1

1

Supply that argument as one list item without the quotes

[..., '-Dwebdriver.firefox.bin=C:\\Program Files (x86)\\Mozilla Developer Preview\\firefox.exe', ...]

And it should work fine

The quotes are only required to tell the command line to take it as one argument, but the list already does that for you, so the quotes are just in the way

Take a look at this answer: ffmpeg through python subprocess fails to find camera

Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62
  • Without the quotes, I'm still getting the error. The reason I put quotes is that I want it to imitate running the actual command in cmd, which works: "C:\Program Files\java\jre7\bin\java.exe" "-Dwebdriver.firefox.bin=\"C:\Program Files (x86)\Mozilla Developer Preview\firefox.exe\"" -jar C:\Users\testing\AppData\Local\Temp\SeleniumServer.jar – chl Jul 12 '17 at 17:09
  • Upon further testing, it seems that this is not a python Popen issue but a windows cmd issue. My previous testing worked only for Cygwin, but never in cmd, so I will try to sort that out first. – chl Jul 12 '17 at 17:48
  • According to https://stackoverflow.com/questions/12891383/correct-quoting-for-cmd-exe-for-multiple-arguments, it seems that the correct way to quote the command is: cmd.exe /C ""C:\Program Files\java\jre7\bin\java.exe" "-Dwebdriver.firefox.bin=C:\Program Files (x86)\Mozilla Developer Preview\firefox.exe" -jar C:\Users\testing\AppData\Local\Temp\SeleniumServer.jar" , which is impossible for the automatic conversion that Popen performs on the list of arguments. – chl Jul 12 '17 at 18:17