Reading stdout and stderr of an external program

M

Murali

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.
 
B

Ben Cartwright

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
 
T

Thomas Jollans

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top