Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Reading stdout and stderr of an external program

Reply
Thread Tools

Reading stdout and stderr of an external program

 
 
Murali
Guest
Posts: n/a
 
      07-02-2007
Hi Python programmers,

I need to be able to read the stdout and stderr streams of an external
program that I launch from my python script. os.system( 'my_prog' +
'>& err.log' ) and was planning on monitoring err.log and to display
its contents. Is this the best way to do this?

Thanks,
Murali.

 
Reply With Quote
 
 
 
 
Ben Cartwright
Guest
Posts: n/a
 
      07-02-2007
> I need to be able to read the stdout and stderr streams of an external
> program that I launch from my python script. os.system( 'my_prog' +
> '>& err.log' ) and was planning on monitoring err.log and to display
> its contents. Is this the best way to do this?


from subprocess import Popen
stdout, stderr = Popen('my_prog').communicate()

--Ben

 
Reply With Quote
 
 
 
 
Thomas Jollans
Guest
Posts: n/a
 
      07-02-2007
On Monday 02 July 2007, Murali wrote:
> Hi Python programmers,
>
> I need to be able to read the stdout and stderr streams of an external
> program that I launch from my python script. os.system( 'my_prog' +
> '>& err.log' ) and was planning on monitoring err.log and to display
> its contents. Is this the best way to do this?


No. The best way to do this is with Popen, as it is portable and avoids the
extranous file.


--
Regards, Thomas Jollans
GPG key: 0xF421434B may be found on various keyservers, eg pgp.mit.edu
Hacker key <http://hackerkey.com/>:
v4sw6+8Yhw4/5ln3pr5Ock2ma2u7Lw2Nl7Di2e2t3/4TMb6HOPTen5/6g5OPa1XsMr9p-7/-6
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading stdout & stderr from a pipe with popen3 Matt Mencel Ruby 1 07-07-2008 03:12 PM
Correctly reading stdout/stderr from subprocess Christoph Haas Python 0 06-13-2006 10:20 PM
Reading stdout and stderr separately ladygrinningsoul Perl 3 04-25-2005 04:25 PM
C external execution - trap stdout + stderr ChokSheak Lau C Programming 4 09-16-2004 07:08 PM
[NUBY] Reading stderr, stdout and the exit status of a process Alexey Verkhovsky Ruby 5 07-22-2004 09:32 PM



Advertisments