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…
有时执行dos命令需要保存返回值 需要导入库subprocess import subprocess p = subprocess.Popen('ping www.baidu.com', shell=True, stdout=subprocess.PIPE) out, err = p.communicate() print out.splitlines()[24:27] for line in out.splitlines(): print line splitlines 是个列表 可以切片操作…