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的turtle库绘制玫瑰教程

利用Python的turtle库绘制玫瑰教程

turtle的文档:https://docs.python.org/3/library/turtle.html 用Python的turtle库绘图是很简单的,闲来无事就画了一个玫瑰花,下...

Python实现的拟合二元一次函数功能示例【基于scipy模块】

Python实现的拟合二元一次函数功能示例【基于scipy模块】

本文实例讲述了Python实现的拟合二元一次函数功能。分享给大家供大家参考,具体如下: 背景: 使用scipy拟合一元二次函数。 参考: HYRY Studio-《用Python做科学计...

python实现身份证实名认证的方法实例

python实现身份证实名认证的方法实例

前言 本文主要给大家介绍了关于python实现身份证实名认证的方法,文中通过示例代码介绍的非常详细,下面话不多说了,来一起看看详细的介绍吧 方法如下 一、首先我们选用了阿里云的身份证实名...

Django stark组件使用及原理详解

Django stark组件使用及原理详解

 stark组件是仿照django的admin模块开发的一套组件,它的作用是在网页上对注册的数据表进行增删改查操作 一、配置 1、创建stark应用,在settings.py...

使用python的pandas库读取csv文件保存至mysql数据库

第一:pandas.read_csv读取本地csv文件为数据框形式 data=pd.read_csv('G:\data_operation\python_book\chapter5\...