From:
python中获取shell命令输出的方法:
1.
import subprocessoutput = subprocess.Popen(['ls','-l'],stdout=subprocess.PIPE,shell=True).communicate()print output[0]
2.
import commandsreturn_code, output = commands.getstatusoutput('ls -l')
3.
import osprocess = os.popen('ls -l') # return fileoutput = process.read() process.close()