Return Text from popen

Casey Bralla Nobody at Nowhere.com
Sat Oct 15 20:22:59 EDT 2005


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



More information about the Python-list mailing list