By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,898 Members | 1,383 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,898 IT Pros & Developers. It's quick & easy.

Reading stdout and stderr of an external program

P: n/a
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.

Jul 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Jul 2 '07 #2

P: n/a
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
Jul 2 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.