[英]how to run this command line sentence using subprocess?
如何在子过程中运行这句话?
./deb -address 12.345.66.3:6000 -file ./234.csv -key "-key" -secret "password" -id "1234" -insert line
subprocess.call(["","","",""]) but when "" comes like here in key how to use its `"" -key ""` or `'" -key "'`
需要输入
您可以在shell
直接运行整个命令,方法是用单引号引起来并使用shell=True
参数:
subprocess.call('./deb -address 12.345.66.3:6000 -file ./234.csv -key "-key" -secret "password" -id "1234" -insert line', shell=True)
但我建议您利用shlex.split
进行拆分并为您生成正确的转义命令列表,以便无需使用shell即可运行它:
import shlex
command = shlex.split('./deb -address 12.345.66.3:6000 -file ./234.csv -key "-key" -secret "password" -id "1234" -insert line')
subprocess.call(command)
FWIW,您应该在受支持的版本上使用subprocess.run
而不是subprocess.call
(和兄弟)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.