February 26th, 2003, 11:03 AM
getting output from command that isn't STDIN
I need to get the output from mencoder as it encodes videos. Most of it can be retrieved easily enough, but after the initial blurb, it then displays a progress meter with various information including percentage complete, and that stays on the same line, if you get me, like wget's progress meter.
That lien doesn't get picked up through STDTIN or STDERR... I only get the last time that line is refreshed (when it's done) which isn't much use. How can I grab this output?
The code atm is like this:
pipe = popen(command)
line = pipe.readline()
if line == '':
February 26th, 2003, 12:11 PM
Sounds like it's using buffered I/O. You probably want it to be unbuffered, call os.popen (btw, I don't know why you did from os import popen or the even worse from os import * - it's considered bad Python style) like so:
The os.popen command takes arguments similar to the file builtin constructor. The 0 is for unbuffered I/O.
pipe = os.popen(command, 'r', 0)
February 26th, 2003, 07:43 PM
Hrm, that didn't work
I got this from comp.lang.python:
pipe = popen(command, 'r').fileno()
data = os.read(pipe, 3000)
if not data:
which I'm also fiddling around with ???
Last edited by telex4; February 26th, 2003 at 07:51 PM.