Calling a program and read its stdout (UNIX)

Mikael Olofsson mikael at isy.liu.se
Tue May 9 12:07:18 EDT 2000


On 09-May-00 Thomas Thiele wrote:
 >  Hallo!
 >  
 >  I want to call a (shell-)command from a python program and read its
 >  standart output. I also want to set the user and the enviroment before.
 >  At first I did the following: I forked a new process and replaced it by
 >  calling execv. But so I'm not able to read the stdout, because I cannot
 >  change
 >  stdout - fileobject.

Assuming you are on unix, the module popen2 is your friend. 

popen2.popen2(cmd) gives you access to stdin and stdout.
popen2.popen3(cmd) gives you access to stdin, stdout, and stderr.

See the Python Library Reference.

/Mikael

-----------------------------------------------------------------------
E-Mail:  Mikael Olofsson <mikael at isy.liu.se>
WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date:    09-May-00
Time:    16:50:26

This message was sent by XF-Mail.
-----------------------------------------------------------------------



More information about the Python-list mailing list