get the output of a cmd via popen2

Ignacio Vazquez-Abrams ignacio at openservices.net
Sat Aug 25 20:47:29 EDT 2001


On Sat, 25 Aug 2001, Rajarshi Guha wrote:

> Hi,
>   I think I'm doing the right thing, but it does'nt seem to be working.
>
> I have a command which I want to run from a Python script and I want to
> capture the output. So I do,
>
> i,o = os.popen2(cmd)
>
> where cmd is the string that represents the command. But on printing o all
> I get is an object representation like:
>
> <open file '(fdopen)', mode 'r' at 0x810d9f8>
>
> Not the output of the program.
>
> Any suggestions as to whats going wrong and how to fix it?
>
> TIA

The problem is that you're not calling the methods of o to get the data from
the file object.

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list