[Tutor] using popen(n) to intercept stdout
Hugo González Monteverde
hugonz-lists at h-lab.net
Thu Feb 16 06:46:09 CET 2006
Hi Tim,
Yes, you're on the right track.
>>>>a,b,c = os.popen3('wt *.py','r')
>>>>res = a.read()
The error you're getting has nothing to do with the result of the
command, but check, from the docs:
popen3( cmd[, mode[, bufsize]])
Executes cmd as a sub-process. Returns the file objects (child_stdin,
child_stdout, child_stderr). Availability: Unix, Windows. New in version
2.0.
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> IOError: [Errno 9] Bad file descriptor
>
>>>
The 'a' variable is supposed to be the process' STDIN, you are supposed
to write to it. So if you want to read, it is the wrong file object, and
it is in write mode, therefore the IOError.
Also check that the above docs are for os.popen(), popen2.popen()
returns filehandles in a different order.
Hugo
More information about the Tutor
mailing list