catching the output of system()

Praveen Pathiyil praveen.pathiyil at wipro.com
Thu Apr 26 03:13:24 EDT 2001


Hi all,

    I am trying to capture the output written to the stdout during an
os.system() call. ( BTW i am trying to invoke the system tftp through
os.system().)

I was trying out the following way.

               (rd, wr) = os.pipe()
                print rd, wr
                dup_stdout = os.dup(1)
                os.dup2(wr, 1)
                ret = os.system(line)

### line contains the tftp command

                res = os.read(rd, 64)
                os.dup2(1, dup_stdout)
                os.fdopen(1, 'a+')
                print res

But i couldn't get the 'stdout' to revert back to the fd of '1'.

If any one has any ideas on this or any more elegant methods of doing
this,
please help me out.

Thanks in advance,
Praveen.






More information about the Python-list mailing list