Python:按顺序运行bash命令
我在目录中的文件中运行一个可执行文件。我的脚本一次转储所有命令。我想在前面的进程终止后按顺序运行Python:按顺序运行bash命令,python,popen,Python,Popen,我在目录中的文件中运行一个可执行文件。我的脚本一次转储所有命令。我想在前面的进程终止后按顺序运行Popen。这是我的剧本: import glob, os, subprocess import sys, re, math exec_path='/Users/me/path/to/exec' for name in glob.glob("*.in"): print name output = name+'.out' args = [exec_path, '-o', out
Popen
。这是我的剧本:
import glob, os, subprocess
import sys, re, math
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)
谢谢您的时间。听起来您需要在继续循环之前结束流程
你的例子可以这样改写
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()
导入全局
导入子流程
exec_path='/Users/me/path/to/exec'
对于glob.glob(“*.in”)中的名称:
印刷品名称
输出=名称+'.out'
args=[exec_路径,'-o',输出,名称]
subprocess.Popen(args).wait()#听起来像是在继续循环之前需要等待进程结束
你的例子可以这样改写
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()
导入全局
导入子流程
exec_path='/Users/me/path/to/exec'
对于glob.glob(“*.in”)中的名称:
印刷品名称
输出=名称+'.out'
args=[exec_路径,'-o',输出,名称]
subprocess.Popen(args.wait())#