我正在尝试从python运行以下命令:
C:\Program Files\Electric Cloud\ElectricCommander\bin\ectool --server server.domain.com login "username" "password"
使用以下代码无法正确调用该命令。
from subprocess import Popen, PIPE
toolLocation = "C:\\Program Files\\Electric Cloud\\ElectricCommander\\bin\\ectool"
parameters = "--server server.domain.com login \"username\" \"password\""
output = Popen([toolLocation, parameters ], stdout=PIPE)
print output.stdout.read()
知道失败的原因吗?
答案 0 :(得分:1)
您只传递一个参数,您需要将每个参数作为列表的元素传递,例如:
from subprocess import Popen, PIPE
toolLocation = "C:\\Program Files\\Electric Cloud\\ElectricCommander\\bin\\ectool"
parameters = ["--server", "server.domain.com", "login", "username", "password"]
output = Popen([toolLocation] + parameters, stdout=PIPE)
print output.stdout.read()