【发布时间】:2011-02-01 06:54:09
【问题描述】:
我了解到,在 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)
调用 child.communicate() 后程序不会继续,而是等待命令完成。有没有其他方法可以跟随输出?
【问题讨论】:
标签: python subprocess