最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python执行系统命令后获取返回值的几种方式集合
时间:2018-05-21 编辑:猪哥 来源:一聚教程网
第一种情况
os.system('ps aux')
执行系统命令,没有返回值
第二种情况
result = os.popen('ps aux') res = result.read() for line in res.splitlines(): print line
执行系统命令,可以获取执行系统命令的结果
p = subprocess.Popen('ps aux',shell=True,stdout=subprocess.PIPE) out,err = p.communicate() for line in out.splitlines(): print line
同上,执行系统命令,可以获取执行系统命令的结果
第三种情况
output = commands.getstatusoutput('ps aux') print output
执行系统命令,并获取当前函数的返回值
-
下一个: PHP区块查询实现方法分析
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27