import os,subprocess
p = subprocess.Popen("df -h", shell=True, stdout=subprocess.PIPE)
out = p.stdout.readlines()
for line in out:
print line.strip()
将df -h的执行结果输出到stdout,再用readlines方法读出来,再print出来
import os,subprocess
x = subprocess.check_output(["date", "+%T"])
print x
这个方法可以将某个命令的结果输出到python