我瞭解到,在Python中執行命令時,我應該使用子進程。 我想要實現的是通過ffmpeg對文件進行編碼,並觀察程序輸出,直到文件完成。 Ffmpeg將進度記錄到stderr。捕獲子進程輸出
如果我嘗試這樣:
child = subprocess.Popen(command, shell=True, stderr=subprocess.PIPE)
complete = False
while not complete:
stderr = child.communicate()
# Get progress
print "Progress here later"
if child.poll() is not None:
complete = True
time.sleep(2)
的PROGRAMM不會繼續調用child.communicate後(),並等待命令完成。有沒有其他的方式來跟蹤輸出?
相關:[Python:從subprocess.communicate()讀取流輸入)(http://stackoverflow.com/q/2715847/4279) – jfs 2015-06-13 13:54:05