Storing Subprocess Results

Karthik Gurusamy kar1107 at
Wed Sep 3 00:31:39 CEST 2008

On Sep 2, 7:16 am, topazcode <t... at> wrote:
> I am using the subprocess module to run some shell commands on a Linux
> system:
> import subprocess
> output ='''ssh server1 "uptime"''', shell=True)
> The above assigns the output variable with a return code, i.e. 0 in
> this case.  How can I actually capture the data returned from
>, rather than just the return code?  I'd like to have
> the output variable contain the uptime string in this case.

Probably commands module is a better choice for your problem:
>>> import commands
>>> commands.getoutput('fortune')
"While money can't buy happiness, it certainly lets you choose your own
\nform of misery."


 Any help
> is appreciated.  Thanks.

More information about the Python-list mailing list