Python monitoring stderr and stdout of a subprocess
I have accomplished the same with ffmpeg. This is a stripped down version of the relevant portions. bufsize=1
means line buffering and may not be needed.
def Run(command): proc = subprocess.Popen(command, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) return procdef Trace(proc): while proc.poll() is None: line = proc.stdout.readline() if line: # Process output here print 'Read line', lineproc = Run([ handbrakePath ] + allOptions)Trace(proc)
Edit 1: I noticed that the subprocess (handbrake in this case) needs to flush after lines to use this (ffmpeg does).
Edit 2: Some quick tests reveal that bufsize=1
may not be actually needed.