[Tutor] captering output of a cmd run using os.system.

Andrew Wilkins toodles@yifan.net
Fri, 1 Jun 2001 17:29:56 +0800


Sorry to do a thread takeover here, but I'm going to anyway :o)
I asked not too long ago but I don't think I got a reply, so I'll just try
again.

(FYI I'm using WinME, with Python 2.1)

I'm not familiar with popen, and I looked through the docs and couldn't find
anything, so I would like to know how this works...

With popen when you pipe to a program, it doesn't bring up the stdout - it
goes straight to the pipe. Is it possible for the output to be directed both
to the pipe and to stdout?

Let's say I have the following:

pipe = os.popen('python t','r')
print pipe.read()

############
t.py should look like:

while 1:
 x=raw_input('')
 print x

How can I get the above to come up as visible? With popen it seems to work
in the background.
Is it possible to also collect input from stdin as well as the pipe? Say if
I wanted to send a response to the raw_input bit through the pipe, or
through the actual stdin...

TIA,
Andrew Wilkins