相关疑难解决方法(0)

捕获子进程输出

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

python subprocess

25
推荐指数
1
解决办法
3万
查看次数

Python:使用stdout从subprocess.call捕获输出

所以我试图保存我的输出,subprocess.call但我不断收到以下错误: AttributeError: 'int' object has no attribute 'communicate'

代码如下:

p2 = subprocess.call(['./test.out', 'new_file.mfj', 'delete1.out'], stdout = PIPE)
output = p2.communicate[0]
Run Code Online (Sandbox Code Playgroud)

python

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×2

subprocess ×1