代码之家  ›  专栏  ›  技术社区  ›  Å těpán vrÅ¡a

Python-使用Popen时意外中断循环

  •  0
  • Å těpán vrÅ¡a  · 技术社区  · 7 年前

    我需要多次调用一个脚本,但参数不同。参数存储在argument_list及其字符串列表中。

    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()
    

    有人知道为什么会这样,我该怎么解决?谢谢你的建议。

    1 回复  |  直到 7 年前
        1
  •  0
  •   jcoppens    7 年前
    python_command = "python another_script.py --server " + argument
    

    Popen的参数必须按顺序排列:

    python_command = ["python", "another_script.py", "--server", argument]
    

    还有一个建议:试着把Popen语句放在 try ... except