#1
  1. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14

    getting output from command that isn't STDIN


    hullo,

    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:

    PHP Code:
    pipe popen(command)
    while 
    1:
            
    line pipe.readline()
            if 
    line == '':
                    break
            print 
    line 
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    14
    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:

    Code:
    pipe = os.popen(command, 'r', 0)
    The os.popen command takes arguments similar to the file builtin constructor. The 0 is for unbuffered I/O.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  4. #3
  5. Wacky hack
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Location
    London, England
    Posts
    513
    Rep Power
    14
    Hrm, that didn't work

    I got this from comp.lang.python:

    pipe = popen(command, 'r').fileno()
    while 1:
    data = os.read(pipe, 3000)
    if not data:
    break
    os.write(1, data)

    which I'm also fiddling around with ???
    Last edited by telex4; February 26th, 2003 at 07:51 PM.

IMN logo majestic logo threadwatch logo seochat tools logo