python中得到shell命令输出的方法:
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()
时间: 2024-10-04 03:10:14