我正在尝试使用Popen(shlex.split(cmd)...
和Popen(cmd.split(' ')...
执行下面的命令,但是在下面遇到错误,我该如何运行该命令或如何调试该错误?
def function_create_cmds(cmd):
print cmd
#proc = Popen(shlex.split(cmd), shell=True, stdout=PIPE, stderr=PIPE)
proc = Popen(cmd.split(' '), stdout=PIPE, stderr=PIPE)
(output, error) = proc.communicate()
return output,error
cmd = "/usr/local/bin/xbs submitproject -notesfile /Users/usernamea/autosubmissionlogs/07162018_133945/milestone/project-375/project-375.plist -version project-1.0.7 /Users/usernamea/wifiroots/project Release"
(output,error) = function_create_cmds(cmd)
print output
print error
错误:
Popen(cmd.split(' '),
INFO: submitproject was unable to locate a submission directory named
Popen(shlex.split(cmd)
xbs requires a command
答案 0 :(得分:0)
不要使用shell=True
,它不需要调用外壳程序来运行您的子进程,因此调用两个进程毫无益处。
proc = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE)
应该工作。如果没有,请提供您在这种情况下遇到的错误。
您总是可以自己分割命令:
subprocess.Popen([
"/usr/local/bin/xbs",
'submitproject',
'-notesfile',
'/Users/usernamea/autosubmissionlogs/07162018_133945/milestone/project-375/project-375.plist',
'-version',
'project-1.0.7',
'/Users/usernamea/wifiroots/project',
'Release',
])