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

相关文章:

  • 2021-07-25
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
猜你喜欢
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2021-05-30
  • 2021-12-10
  • 2022-12-23
相关资源
相似解决方案