执行shell并打印结果

commands模块#可以很方便的取得命令的输出(包括标准和错误输出)和执行状态位

import commands
a,b = commands.getstatusoutput('ls')
a是退出状态
b是输出的结果。
>>> import commands
#执行shell
>>> a,b = commands.getstatusoutput('ls')
>>> print a
0
#打印结果
>>> print b
anaconda-ks.cfg
install.log
install.log.syslog
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。