[Tutor] using popen(n) to intercept stdout

Tim Johnson tim at johnsons-web.com
Thu Feb 16 04:51:27 CET 2006


Hi:

I've got a question about popen2.
Consider the following code: (on linux)

import popen2
fin, fout = popen2.popen2("man nothere")
## interpreter outputs the following:
No manual entry for nothere

The following queries of the returned file objects
give the following:
>>> fin
<open file '<fdopen>', mode 'r' at 0x404935e0>
>>> fout
<open file '<fdopen>', mode 'w' at 0x401758a0>
>>> fin.read()
''

Question:
How do I intercept the first response?
I.E. How do I get "No manual entry for nothere"
into a variable?

The object is to call another process on the same machine and capture
the output of that process, assuming that the child process is writing
to stdout.

thanks
tim

-- 
Tim Johnson <tim at johnsons-web.com>
      http://www.alaska-internet-solutions.com


More information about the Tutor mailing list