我有一个从命令行运行的程序,如下所示:
$ program a.txt b.txt
该程序需要两个文本文件作为参数。 我正在尝试编写一个Python 3.2脚本来运行上面的程序。 我应该怎么做? 目前,我正在尝试像这样使用subprocess
模块:
import subprocess
with open("a.txt", mode="r") as file_1:
with open("b.txt", mode="r") as file_2:
cmd = ['/Users/me/src/program', file_1, file_2]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in process.stdout:
print(line)
我阅读了这篇帖子和这篇帖子,它们似乎描述了与我的问题类似的解决方案。不幸的是,在阅读了这些帖子之后,我仍然无法使我的Python代码运行程序。
有人能帮忙吗?谢谢!
wait
方法 - 我之前不知道这个。 - drbunsen