Python 3.x 如何使用python子流程并行运行命令列表
我使用子进程在多个文件上执行perl脚本。该脚本有一个输出参数,我希望每个并行运行的所有输出都写入该输出 我试过的Python 3.x 如何使用python子流程并行运行命令列表,python-3.x,parallel-processing,subprocess,Python 3.x,Parallel Processing,Subprocess,我使用子进程在多个文件上执行perl脚本。该脚本有一个输出参数,我希望每个并行运行的所有输出都写入该输出 我试过的 from subprocess import Popen, PIPE def proc_cmd(cmd_lst, outfile): proc_lst = [] for cmd in cmd_list: with open(outfile, 'w') as out: run_proc = Popen(cmd, stdout=o
from subprocess import Popen, PIPE
def proc_cmd(cmd_lst, outfile):
proc_lst = []
for cmd in cmd_list:
with open(outfile, 'w') as out:
run_proc = Popen(cmd, stdout=out, stderr=PIPE, shell=True)
proc_lst.append(run_proc)
for proc in proc_lst:
if proc.poll() is None:
proc.wait()
outfile = 'results.txt'
cmd_lst = [['perl script.pl -i', 'f1.txt', '-s', 'h1.txt', '-o', 'results.txt'], ['perl script.pl -i', 'f2.txt', '-s', 'h2.txt', '-o', 'results.txt'], ['perl script.pl -i', 'f3.txt', '-s', 'h3.txt', '-o', 'results.txt']]
proc_cmd(cmd_lst, outfile)
当我运行outfile时,没有任何内容写入它。事实上,它看起来根本不起作用,也没有打印错误。我应该在我的输出文件中收集所有结果。我需要一些帮助当您直接使用perl运行perl脚本时,perl脚本是否写入
results.txt
?是的,它通常写入result.txt