Return Text from popen

Micah Elliott mde at micah.elliott.name
Sat Oct 15 21:46:40 EDT 2005


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
<mde at micah.elliott.name>



More information about the Python-list mailing list