Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old February 26th, 2003, 10:03 AM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
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 

Reply With Quote
  #2  
Old February 26th, 2003, 11:11 AM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
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.

Reply With Quote
  #3  
Old February 26th, 2003, 06:43 PM
telex4's Avatar
telex4 telex4 is offline
Wacky hack
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2001
Location: London, England
Posts: 512 telex4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 25 m 29 sec
Reputation Power: 8
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 06:51 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > getting output from command that isn't STDIN


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway