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

相关文章

Python3.5装饰器原理及应用实例详解

Python3.5装饰器原理及应用实例详解

本文实例讲述了Python3.5装饰器原理及应用。分享给大家供大家参考,具体如下: 1、装饰器: (1)本质:装饰器的本质是函数,其基本语法都是用关键字def去定义的。 (2)功能:装饰...

Python 实现毫秒级淘宝抢购脚本的示例代码

本篇文章主要介绍了Python 通过selenium实现毫秒级自动抢购的示例代码,通过扫码登录即可自动完成一系列操作,抢购时间精确至毫秒,可抢加购物车等待时间结算的,也可以抢聚划算的商品...

Python 中pandas索引切片读取数据缺失数据处理问题

Python 中pandas索引切片读取数据缺失数据处理问题

引入   numpy已经能够帮助我们处理数据,能够结合matplotlib解决我们数据分析的问题,那么pandas学习的目的在什么地方呢? numpy能够帮我们处理处理数值型数据,但是这...

python提取字典key列表的方法

本文实例讲述了python提取字典key列表的方法。分享给大家供大家参考。具体如下: 这段代码可以把字典的所有key输出为一个数组 d2 = {'spam': 2, 'ham': 1...

matplotlib实现热成像图colorbar和极坐标图的方法

matplotlib实现热成像图colorbar和极坐标图的方法

热成像图 %matplotlib inline from matplotlib import pyplot as plt import numpy as np def f(x,...