Return Text from popen

C

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!
 
M

Micah Elliott

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top