Return Text from popen

2005-10-15 Thread Casey Bralla
I know this problem has a very simple answer, but I've checked the web and I
don't understand the answers that I've found.

How do I return text from a standard Linux command?

For example:  I want to read the stdout results of a typical linux command
(such as df) into a Python variable.

I've tried these techniques:

 result = os.system(df)
 It dumps the stdout to a screen and puts the result code into result

 result = popen2(df)
 It gives me a tuple of the stdin  stdout pipes, which I don't know how to
harvest into the actual stdout result.


Can someone give me a brief code example of how to get the actual text
result from the linux command into a Python variable?  Thanks!

-- 
Casey Bralla
Chief Nerd in Residence
The NerdWorld Organisation
http://www.NerdWorld.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return Text from popen

2005-10-15 Thread Micah Elliott
On Oct 15, Casey Bralla wrote:
 How do I return text from a standard Linux command?
 
 For example:  I want to read the stdout results of a typical linux
 command (such as df) into a Python variable.

 from os import popen
 p = popen(df)
 p
open file 'df', mode 'r' at 0xf6f685e0
 df_out = p.read()
 p.close()
 p
closed file 'df', mode 'r' at 0xf6f685e0
 print df_out

-- 
Micah Elliott
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list