popen2 results

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Wed Apr 25 09:56:28 CEST 2007


Hello guys,

 

I've recently ported my application from bash to python, however there are
still a few bash line utilities I -have- to use in the application as there
isn't any alternative available to me. In the old days of bash I would have
grep'd the output from these commands to determine the outcome.

 

I'm now using popen2 to run the command which works a charm, but I'm
struggling to parse the results of the function, has anyone had any
experience with this? I've found a few suggested solutions dotted around,
such as this one.

 

     import os

 

     def filtered(command, source):

         dest, result = os.popen2(command)

         dest.write(source)

         dest.close()

         try:

              return result.read()

         finally:

              result.close()

 

But to be honest I'm struggling to get it to do anything as it doesn't
states what the 'source' object is or should be.

 

Thanks for any help guys, I'm just looking to capture the output from the
command and then I can go about a little REGEX on it.

 

Thanks,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070425/55851544/attachment.html>


More information about the Python-list mailing list