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

相关文章

python实现给scatter设置颜色渐变条colorbar的方法

python实现给scatter设置颜色渐变条colorbar的方法

python设置scatter颜色渐变的方法 参考代码如下: <span style="font-size:18px;">import matplotlib.pyplot...

Python判断两个对象相等的原理

概述 大部分的python程序员平时编程的时候,很少关心两个对象为什么相等,因为教程和经验来说,他们就应该相等,比如1==1就应该返回True,可是当我们想要定义自己的对象或者修改默认的...

pytorch + visdom CNN处理自建图片数据集的方法

pytorch + visdom CNN处理自建图片数据集的方法

环境 系统:win10 cpu:i7-6700HQ gpu:gtx965m python : 3.6 pytorch :0.3 数据下载 来源自Sasank Chilamkurthy 的...

Python使用try except处理程序异常的三种常用方法分析

本文实例讲述了Python使用try except处理程序异常的三种常用方法。分享给大家供大家参考,具体如下: 如果你在写python程序时遇到异常后想进行如下处理的话,一般用try来处...

使用python调用zxing库生成二维码图片详解

使用python调用zxing库生成二维码图片详解

(1)安装Jpype 用Python调用jar包需要安装jpype扩展,在Ubuntu上可以直接使用apt-get安装jpype扩展 $ sudo apt-get install...