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
时间: 2024-12-28 20:59:48