commands模块用于调用shell命令有3中方法:commands.getstatus() 返回执行状态commands.getoutput() 返回执行结果commands.getstatusoutput() 返回一个元组,执行状态和执行结果其他执行shell命令的方法还有:1.os.sy.....
分类:
编程语言 时间:
2015-01-14 09:37:31
阅读次数:
609
我们这次讲的是利用commands模块执行Linux shell命令,当我们用Python写运维脚本时,经常需要执行linux shell的命令,Python中的commands模块专门用于调用Linux shell命令,并返回状态和结果,下面是commands模块的3个主要函数:1.comman....
分类:
编程语言 时间:
2014-11-29 06:43:36
阅读次数:
189
我们这次讲的是利用commands模块执行Linux shell命令,当我们用Python写运维脚本时,经常需要执行linux shell的命令,Python中的commands模块专门用于调用Linux shell命令,并返回状态和结果,下面是commands模块的3个主要函数:
1.commands.getoutput('shell command')
2.commands.getstat...
分类:
编程语言 时间:
2014-11-29 00:16:40
阅读次数:
376
1.用os.system(cmd) 不过取不了返回值2.用os.popen(cmd) 要得到命令的输出内容,只需再调用下read()或readlines()等 如a=os.popen(cmd).read()3.用commands模块。其实也是对popen的封装。此模块主要有如下方法commands....
分类:
编程语言 时间:
2014-11-11 22:39:06
阅读次数:
298
1. python中使用shell命令有多种方法,我自己觉得比较好用的是用commands模块:import commandsa,b = commands.getstatusoutput("ls -Al")a是退出状态(int类型), b是shell 命令的输出结果python -> shell:1...
分类:
编程语言 时间:
2014-08-12 13:11:34
阅读次数:
228