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的tkinter布局之简单的聊天窗口实现方法

python的tkinter布局之简单的聊天窗口实现方法

本文实例展示了一个python的tkinter布局的简单聊天窗口。分享给大家供大家参考之用。具体方法如下: 该实例展示的是一个简单的聊天窗口,可以实现下方输入聊天内容,点击发送,可以增加...

Python读取实时数据流示例

1、#coding:utf-8 chose = [ ('foo',1,2), ('bar','hello'), ('foo',3,4) ] def do_foo(x,y...

在django-xadmin中APScheduler的启动初始化实例

环境: python3.5.x + django1.9.x + xadmin-for-python3 APScheduler做为一个轻量级和使用量很多的后台任务计划(scheduler)...

Linux 修改Python命令的方法示例

Linux 修改Python命令的方法示例

Linux默认python命令指向的是/usr/bin下的python,这个python指向同目录下python2,以及pip默认也是python2的pip,想修改成pip指向pip3,...

python实现给微信公众号发送消息的方法

本文实例讲述了python实现给微信公众号发送消息的方法。分享给大家供大家参考,具体如下: 现在通过发微信公众号信息来做消息通知和告警已经很普遍了。最常见的就是运维通过zabbix调用s...