有时执行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 是个列表 可以切片操作…