Python资料之commands模块
commands模块是python的内置模块,他共有三个函数,使用help(commands)可以查看到。
注:在3.x版本总,getstatus()方法被移除,getoutput()和getstatusoutput()被放到了subprocess模块中。
FUNCTIONSgetoutput(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
Python资料之commands模块相关推荐
- python commands_python之commands模块
要获得shell命令的输出只需要`cmd`命令就可以了, 需要得到命令执行的状态则需要判断$?的值, 在Python中有一个模块commands也很容易做到以上的效果. 看一下三个函数: 1). co ...
- python commands执行不连续_[Python] 利用commands模块执行Linux shell命令
用Python写运维脚本时,经常需要执行linux shell的命令,Python中的commands模块专门用于调用Linux shell命令,并返回状态和结果,下面是commands模块的3个主要 ...
- python commands用法_python之commands模块(执行Linux Shell命令)
commands模块 用于执行Linux shell命令,要获得shell命令的输出只需要在后面参数写入('命令')就可以了. 需要得到命令执行的状态则需要判断$?的值, 在Python中有一个模块c ...
- python中commands模块
commands模块是python的内置模块,他共有三个函数,使用help(commands)可以查看到. 注:在3.x版本总,getstatus()方法被移除,getoutput()和getstat ...
- python commands模块_python之commands和subprocess入门介绍(可执行shell命令的模块)
一.commands模块 1.介绍 当我们使用Python进行编码的时候,但是又想运行一些shell命令,去创建文件夹.移动文件等等操作时,我们可以使用一些Python库去执行shell命令. com ...
- python commands.getoutput_Python3中用什么替换commands模块的getstatusoutput()
先翻译一段文章:https://stackoverflow.com/questions/11344557/replacement-for-getstatusoutput-in-python-3 在最后 ...
- Python 五个常用模块资料 os sys time re built-in
1.os模块 os模块包装了不同操作系统的通用接口,使用户在不同操作系统下,可以使用相同的函数接口,返回相同结构的结果. os.name:返回当前操作系统名称('posix', 'nt', ' ...
- Python标准库threading模块Condition原理浅析
Python标准库threading模块Condition原理浅析 本文环境python3.5.2 threading模块Condition的实现思路 在Python的多线程实现过程中,在Linux平 ...
- Python图像处理,cv2模块,OpenCV实现人脸检测蔡徐坤
前言 利用Python实现OpenCV实现人脸检测,废话不多说~ 让我们愉快地开始吧~ 开发工具 Python版本: 3.6.4 相关模块: cv2模块: 以及一些Python自带的模块. 环境搭建 ...
最新文章
- (转)Android笔记--handler机制
- LAMP笔记之MySQL高阶篇(5)
- 总结:二分法题目汇总 以及二分法模板
- GitHub轻松阅读微服务实战项目流程详解【第一天:数据库表设计及其环境搭建、项目运行】
- CCF201312-3 最大的矩形(100分)
- python操作excel_使用Python操作Excel时必学的3个库
- java单终端登陆_配置终端服务单一登录
- 中科大计算机复试题目,08中科大11系(计算机)复试
- HMS数据库设置和优化
- c 开发服务器的性能,高性能网络编程(三):下一个10年,是时候考虑C10M并发问题了...
- 学网络编程很好的参考源码
- C语言中fgetc函数返回值为什么是int?
- Httpd Forbidden:You don't have permission to access /index.html on this server.
- 2019.2.18 模板的创建和自定义子模板文件(single.php 等)
- Coursera吴恩达机器学习week4笔记
- Python WindowsError
- java图片改变分辨率并保存
- 台湾国立大学郭彦甫Matlab教程笔记(5)structured programming
- 2022-2028全球月桂醇磷酸酯(MAE)行业调研及趋势分析报告
- SDUT实验六7-6 sdut- C语言实验-矩阵转置
热门文章
- html5设计礼品盒效果,30个创意包装设计例子
- 关于Dracula伯爵的传说
- VSCode 插件(分类查找)
- format函数python是什么意思_python中format函数指的是什么意思
- box–jenkins模型_教程– EMFStore –模型库
- 12306现象的根本原因
- 【已解决】报错qt.qpa.plugin: Could not load the Qt platform plugin “windows“ in “...“ even though it was
- 软件测试 3(边界值) -- 健壮性测试
- 自动化工具软件详细列举
- cubemx 读卡器_STM32CubeMX基于SD卡的FATFS文件系统测试