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

yipeiwu_com6年前Python基础

#!/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设计】~

相关文章

在Windows8上的搭建Python和Django环境

在Windows8上的搭建Python和Django环境

先从搭建环境开始。作为一个Python初学者来说,一个趁手的编译器是很重要的,本想用VS来开发Python,但是感觉实际开发中没有几家公司会用VS来开发Python,没办法就换成了MyE...

Python元组常见操作示例

本文实例讲述了Python元组常见操作。分享给大家供大家参考,具体如下: 不能修改的列表就叫做元组。 1 访问元素 元组是使用圆括号来标识的。 定义好元组后, 我们就可以使用索引来访问其...

简单介绍Python中的RSS处理

RSS 是一个可用多种扩展来表示的缩写:“RDF 站点摘要(RDF Site Summary)”、“真正简单的辛迪加(Really Simple Syndication)”、“丰富站点摘...

pycharm配置当鼠标悬停时快速提示方法参数

pycharm配置当鼠标悬停时快速提示方法参数

1、配置pycharm 依次点击"File"-->"Settings",进入"Editor"-->"General",勾选"Other"下的“Show quick docum...

python数值基础知识浅析

内置数据类型 Python的内置数据类型既包括数值型和布尔型之类的标量,也包括 更为复杂的列表、字典和文件等结构。 数值 Python有4种数值类型,即整数型、浮点数型、复数型和布...