python commands模块的适用方式
作者:以我丶之姓 时间:2022-02-26 19:38:14
commands模块的适用
commands模块是python的内置模块,他共有三个函数,使用help(commands)可以查看到
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、 commands.getstatusoutput(cmd)返回一个元组(status,output)
status代表的shell命令的返回状态,如果成功的话是0;output是shell的返回的结果
>>> import commands
>>> status, output = commands.getstatusoutput("ls")
>>> print status
0
>>> print output
atom:
bookstore
cookie.py~
2、返回ls -ld file执行的结果
commands.getstatus(file)
3、判断Shell命令的输出内容
commands.getoutput(cmd)
>>> print commands.getoutput("ls")
atom:
bookstore
cookie.py~
commands 方法
commands 模块是 Python 的内置模块,它主要有三个函数:
函数 | 说明 |
---|---|
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. |
来源:https://www.jianshu.com/p/d29b8a2119ad
标签:python,commands,模块
0
投稿
猜你喜欢
Python使用百度api做人脸对比的方法
2023-08-18 12:52:24
详解如何利用Python进行客户分群分析
2023-04-25 16:47:09
python实现logistic分类算法代码
2021-12-24 14:19:15
Django中对通过测试的用户进行限制访问的方法
2021-08-27 16:42:46
Python os模块中的isfile()和isdir()函数均返回false问题解决方法
2022-04-16 19:40:58
python通过colorama模块在控制台输出彩色文字的方法
2023-07-23 00:35:51
python读取中文txt文本的方法
2021-06-10 03:55:51
关于计算到期时间的问题
2009-05-26 15:51:00
MSSQL优化之探索MSSQL执行计划(转)
2011-11-03 17:16:21
asp生成UTF-8格式的文件方法
2008-01-26 20:59:00
PHP设计模式之中介者模式浅析
2023-05-25 04:07:16
php实现HTML实体编号与非ASCII字符串相互转换类实例
2023-11-15 06:12:14
优化Oracle库表设计的若干方法
2010-07-16 13:24:00
强悍的Python读取大文件的解决方案
2021-12-26 19:25:28
Python使用mmap实现内存映射文件操作
2022-04-26 14:37:19
Python代码实现列表分组计数
2022-11-03 07:58:38
移动网站开发:标记语言
2010-06-08 13:42:00
Python实现壁纸下载与轮换
2022-07-01 19:19:19
ul设置浮动后不能自适应高度
2011-01-25 12:48:00
揭秘SQL Server 2008性能和可扩展性
2009-03-10 14:47:00