我想按順序運行多個python程序,我想捕獲stdout或每個進程的輸出使用臨時文件或者(如果有更好的方法可以做到這一點)。將由文件或從進程1生成的多個文件的輸出將用作下一個進程的輸入。怎麼做?從子進程stdout捕獲多個文件到一個臨時文件用於下一個子進程
所以我的代碼是這樣的:
# multiple files
for file in files:
P1 = Popen('python Prog1.py' + ' ' + file, stdout=PIPE , stderr=STDOUT,shell=True)
# Now I want to capture the output to files so can be used for the next process
# It didn't work
l_out_files.append(P1.stdout)
# Prog2 require if the input file is more than one to have them separated by space
P2 = Popen('python Prog2.py' + ' ' + ' '.join(l_out_files), stdout=PIPE , stderr=STDOUT,shell=True)
非常感謝球員,
最佳
什麼是你真正想傳球,都是p1和p2在循環? –
@PadraicCunningham我修正了這個問題,p1進入循環,但是位於p2。 – BioInformatician
所以Prog2.py需要一串文件名?另外,爲什麼不從python做所有這些,你的程序實際上在做什麼? –