我正在*.in目錄中的一堆文件上運行一個可執行文件。我的腳本一次轉儲所有命令。我想Popen在較早的進程終止后按順序運行。這是我的腳本:import glob, os, subprocessimport sys, re, mathexec_path='/Users/me/path/to/exec'for name in glob.glob("*.in"): print name output = name+'.out' args = [exec_path, '-o', output, name] subprocess.Popen(args)謝謝你的時間。
1 回答

GCT1015
TA貢獻1827條經驗 獲得超4個贊
聽起來你需要等待你的過程結束才能繼續循環。
你的例子可以這樣重寫;
import glob
import subprocess
exec_path='/Users/me/path/to/exec'
for name in glob.glob("*.in"):
print name
output = name + '.out'
args = [exec_path, '-o', output, name]
subprocess.Popen(args).wait() # <- I've added .wait()
添加回答
舉報
0/150
提交
取消