Python-使用Popen时循环意外中断
我需要多次调用一个脚本,但参数不同。参数存储在参数列表及其字符串列表中Python-使用Popen时循环意外中断,python,loops,for-loop,subprocess,popen,Python,Loops,For Loop,Subprocess,Popen,我需要多次调用一个脚本,但参数不同。参数存储在参数列表及其字符串列表中 for argument in argument_list: python_command = "python another_script.py --server " + argument p = Popen(python_command,shell=True, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() 问题是,在一次迭代
for argument in argument_list:
python_command = "python another_script.py --server " + argument
p = Popen(python_command,shell=True, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
问题是,在一次迭代之后,脚本从for循环中断,即使参数_列表中仍然有项目,并且循环中没有中断
有人知道为什么会发生这种情况,我该如何解决?谢谢你的建议
python_command = "python another_script.py --server " + argument
Popen的参数必须按顺序排列:
python_command = ["python", "another_script.py", "--server", argument]
还有一个建议:尝试将Popen语句放在
Try。。。除了
,因此如果出现错误,您将获得有关原因的更详细解释。问题最有可能出现在您未在此处显示的代码部分。谢谢,这解决了问题。将尝试使用try。。。除外:)