The method of getting shell command output in Python

python to get shell command output :

1.

import subprocess

output = subprocess.Popen(['ls','-l'],stdout=subprocess.PIPE,shell=True).commun
icate()
print output[0]

2。

import commands

return_code, output = commands.getstatusoutput('ls -l')

3。

import os

process = os.popen('ls -l') # return file
output = process.read()
process.close()

the original address: http://www.cnblogs.com/snow-backup/p/5035792.html

Read More: