我了解到在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)
Run Code Online (Sandbox Code Playgroud)
调用child.communicate()并等待命令完成后,程序不会继续.还有其他方法可以跟随输出吗?