运行多个子进程命令

时间:2015-09-29 15:36:11

标签: python

我在获取Python AVL时遇到了麻烦。

我需要按顺序运行两个命令并获取整个结果的字符串以供进一步处理:

  1. wine /Applications/avl.exe ~/documents/aerodynamics_project/input_cases/somefile.avl 这会显示问题的命令提示符。
  2. OPER运行案例
  3. 理想情况下,我希望将整个输出传递给字符串。我无法弄清楚如何做到这一点。目前的代码:

    p = subprocess.Popen("wine /Applications/avl.exe ~/documents/aerodynamics_project/input_cases/1_0.2_-0.26.avl", shell = True)
    time.sleep(3)
    text = p.communicate("OPER")
    print(text)
    

    它运行第一个命令(在终端中显示结果),然后不执行任何操作。替换与call之间的通信只返回AttributeError: 'Popen' object has no attribute 'call',因此它显然可以运行到那么远。

1 个答案:

答案 0 :(得分:0)

你可以尝试传递显式参数吗?而且,使用stdin作为PIPE

p = subprocess.Popen("wine /Applications/avl.exe ~/documents/aerodynamics_project/input_cases/1_0.2_-0.26.avl", shell = True, stdin=subprocess.PIPE).stdin
time.sleep(3)
text = p.communicate(input="OPER")[0]
print(text.decode())
相关问题