关于系统属性 arg 中的 python:subprocess.Popen 空间 | 珊瑚贝

subprocess.Popen spaces within system property arg


将命令作为列表传递时,subprocess.Popen 将自动引用有空格的参数。但是,如果我使用具有如下空格的系统属性运行 java:

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

,会报错:
‘C:\\\\Program’ 无法识别错误
,我认为这是因为 Popen 会在看到空格时在整个参数周围插入引号,并转义其余的双引号。如果我想继续使用 Popen 命令,我不确定如何解决这个问题:

1
2
3
4
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’])
  • 你想做什么详细说明….
  • 为什么是 cmd.exe?添加shell解释层会引入您原本不会有的复杂性。
  • 我认为需要 cmd.exe,因为我没有使用 shell=True。


将该参数作为一个不带引号的列表项提供

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

它应该可以正常工作

引号只需要告诉命令行将其作为一个参数,但列表已经为你做了,所以引号只是在

看看这个答案:ffmpeg through python subprocess failed to find camera

  • 没有引号,我仍然会收到错误消息。我加引号的原因是我希望它模仿在 cmd 中运行实际命令,该命令有效:”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
  • 经过进一步测试,这似乎不是 python Popen 问题,而是 windows cmd 问题。我之前的测试只适用于 Cygwin,但从不在 cmd 中,所以我会先尝试解决这个问题。
  • 根据stackoverflow.com/questions/12891383/…,似乎引用命令的正确方法是: 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” ,这是Popen在参数列表。


来源:https://www.codenong.com/45062603/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_10074.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?