Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-使用Popen时循环意外中断_Python_Loops_For Loop_Subprocess_Popen - Fatal编程技术网

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。。。除外:)