python 捕获 shell/bash 脚本的输出结果实例


Posted in Python onJanuary 04, 2017

#!/usr/bin/python
## get subprocess module
import subprocess
 
## call date command ##
p = subprocess.Popen("date", stdout=subprocess.PIPE, shell=True)
 
## Talk with date command i.e. read data from stdout and stderr. Store this info in tuple
## Interact with process: Send data to stdin. Read data from stdout and stderr,
## until end-of-file is reached.Wait for process to terminate. The optional input
## argument should be a string to be sent to the child process, or None,
## if no data should be sent to the child. ##
(output, err) = p.communicate()
 
## Wait for date to terminate. Get return returncode ##
p_status = p.wait()
print "Command output : ", output
print "Command exit status/return code : ", p_status
 
## from: http://www.cyberciti.biz/faq/python-run-external-command-and-get-output/

以上就是小编为大家带来的python 捕获 shell/bash 脚本的输出结果实例全部内容了,希望大家多多支持三水点靠木~

Python 相关文章推荐
python 获取文件列表(或是目录例表)
Mar 25 Python
举例讲解Python中的身份运算符的使用方法
Oct 13 Python
Python比较2个时间大小的实现方法
Apr 10 Python
Django后台获取前端post上传的文件方法
May 28 Python
在Python中定义一个常量的方法
Nov 10 Python
Python制作exe文件简单流程
Jan 24 Python
使用python实现mqtt的发布和订阅
May 05 Python
Python数据类型之Set集合实例详解
May 07 Python
Pytorch 定义MyDatasets实现多通道分别输入不同数据方式
Jan 15 Python
pytorch实现建立自己的数据集(以mnist为例)
Jan 18 Python
基于python3生成标签云代码解析
Feb 18 Python
Python中的xlrd模块使用整理
Jun 15 Python
python 捕获shell脚本的输出结果实例
Jan 04 #Python
完美解决Python2操作中文名文件乱码的问题
Jan 04 #Python
python去除空格和换行符的实现方法(推荐)
Jan 04 #Python
python去掉行尾的换行符方法
Jan 04 #Python
python对json的相关操作实例详解
Jan 04 #Python
python的random模块及加权随机算法的python实现方法
Jan 04 #Python
python 实现红包随机生成算法的简单实例
Jan 04 #Python
You might like
pw的一个放后门的方法分析
2007/10/08 PHP
php 定界符格式引起的错误
2011/05/24 PHP
那些年一起学习的PHP(三)
2012/03/22 PHP
基于initPHP的框架介绍
2013/04/18 PHP
Ubuntu12下编译安装PHP5.3开发环境
2015/03/27 PHP
javascript实现保留两位小数的多种方法
2015/12/18 Javascript
基于jQuery实现收缩展开功能
2016/03/18 Javascript
Web前端新人笔记之jquery入门心得(新手必看)
2016/05/17 Javascript
jquery.validate使用详解
2016/06/02 Javascript
Easyui笔记2:实现datagrid多行删除的示例代码
2017/01/14 Javascript
angular实现form验证实例代码
2017/01/17 Javascript
JS中Attr的用法详解
2017/10/09 Javascript
layui-table表复选框勾选的所有行数据获取的例子
2019/09/13 Javascript
[01:10:49]Secret vs VGJ.S 2018国际邀请赛淘汰赛BO3 第二场 8.24
2018/08/25 DOTA
python 生成不重复的随机数的代码
2011/05/15 Python
python绘图库Matplotlib的安装
2014/07/03 Python
Python根据指定日期计算后n天,前n天是哪一天的方法
2018/05/29 Python
PyQT实现菜单中的复制,全选和清空的功能的方法
2019/06/17 Python
django创建超级用户时指定添加其它字段方式
2020/05/14 Python
Python内置函数及功能简介汇总
2020/10/13 Python
pandas处理csv文件的方法步骤
2020/10/16 Python
Canvas实现贝赛尔曲线轨迹动画的示例代码
2019/04/25 HTML / CSS
美国克罗格超市在线购物:Kroger
2019/06/21 全球购物
上课迟到检讨书100字
2014/01/11 职场文书
授权委托书样本及填写说明
2014/09/19 职场文书
幼儿园感恩节活动方案
2014/10/06 职场文书
终止或解除劳动合同及劳动关系的证明书
2014/10/06 职场文书
2014年综治维稳工作总结
2014/11/17 职场文书
2014年社区妇联工作总结
2014/12/02 职场文书
开展警示教育活动总结
2015/05/09 职场文书
交通事故被告答辩状
2015/05/22 职场文书
一个独生女的故事观后感
2015/06/04 职场文书
生日赠语
2015/06/23 职场文书
暑期家教宣传单
2015/07/14 职场文书
openstack中的rpc远程调用的方法
2021/07/09 Python
Go语言 详解net的tcp服务
2022/04/14 Golang