Capture subprocess output

Posted by schneck on Stack Overflow See other posts from Stack Overflow or by schneck
Published on 2010-03-26T17:19:50Z Indexed on 2010/03/26 17:23 UTC
Read the original article Hit count: 149

Filed under:
|

Hi there,

I learned that when executing commands in Python, I should use subprocess. What I'm trying to achieve is to encode a file via ffmpeg and observe the program output until the file is done. Ffmpeg logs the progress to stderr.

If I try something like this:

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)

the programm does not continue after calling child.communicate() and waits for the command to complete. Is there any other way to follow the output?

© Stack Overflow or respective owner

Related posts about python

Related posts about subprocess