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

posted on 2017-04-12 18:21  Rohero  阅读(13837)  评论(0编辑  收藏  举报