Python资料之commands模块
2018-01-15 14:34
531 查看
commands模块是python的内置模块,他共有三个函数,使用help(commands)可以查看到。
注:在3.x版本总,getstatus()方法被移除,getoutput()和getstatusoutput()被放到了subprocess模块中。
1、getoutput(cmd):
执行cmd命令,并返回输出的内容,返回结果为str。
2、getstatus(file):
返回执行ls -ld file命令的结果。该函数已被python丢弃,不建议使用。
3、getstatusoutput(cmd)
执行cmd命令,并返回执行的状态和输出的内容,返回结果为int和str。
注:在3.x版本总,getstatus()方法被移除,getoutput()和getstatusoutput()被放到了subprocess模块中。
FUNCTIONS getoutput(cmd) Return output (stdout or stderr) of executing cmd in a shell. getstatus(file) Return output of "ls -ld <file>" in a string. getstatusoutput(cmd) Return (status, output) of executing cmd in a shell.
1、getoutput(cmd):
执行cmd命令,并返回输出的内容,返回结果为str。
>>> import commands >>> out=commands.getoutput("ls -l") >>> print(out) -r-xr-x--- 1 serv service 377 115 16:06 free.py
2、getstatus(file):
返回执行ls -ld file命令的结果。该函数已被python丢弃,不建议使用。
3、getstatusoutput(cmd)
执行cmd命令,并返回执行的状态和输出的内容,返回结果为int和str。
>>> import commands >>> status,out=commands.getstatusoutput("ls -l") >>> print(status) 0 >>> print(out) -r-xr-x--- 1 serv service 377 115 16:06 free.py
相关文章推荐
- python2 commands模块在python3.x被subprocess取代
- 【Python模块】os & linecache & hashlib & commands & sys & time & datetime
- python之commands模块
- python 常用代码学习笔记之commands模块
- python内置模块(commands、sys)
- Python2.x利用commands模块执行Linux shell命令
- Python资料之ramdom模块
- [Python] 利用commands模块执行Linux shell命令
- Python资料之chardet模块
- commands 模块 分类: python 小练习 python Module 2014-01-13 14:27 392人阅读 评论(0) 收藏
- python中的commands模块,执行出错:'{' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
- Python 五个常用模块资料 os sys time re built-in
- [Python2.x] 利用commands模块执行Linux shell命令
- python模块commands
- 这是我见过最完整的模块资料!Python有这样的资源,很快就入门!
- Python模块 os commands sys
- Python的logging模块、os模块、commands模块与sys模块
- 关于python模块循环导入(circular imports)/相对导入(Relative Imports)/绝对导入(Absolute Imports)的官方资料
- python3.x安装模块的setup.py出现 " error: no commands supplied " 错误
- python-commands模块的适用