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实现E-Mail收集插件实例教程

Python实现E-Mail收集插件实例教程

__import__函数 我们都知道import是导入模块的,但是其实import实际上是使用builtin函数import来工作的。在一些程序中,我们可以动态去调用函数,如果我们知道...

python logging日志模块的详解

python logging日志模块的详解 日志级别 日志一共分成5个等级,从低到高分别是:DEBUG INFO WARNING ERROR CRITICAL。 DEBUG:详细的信...

python 实现快速生成连续、随机字母列表

0.摘要 本文介绍了生成连续和随机字母表的方法,用于快速生成大量字母数据。 主要使用chr()函数,将数字通过ASCII表转换为相应字母。 1.chr() 函数 chr() 用一个范围在...

pyqt5的QComboBox 使用模板的具体方法

pyqt5的QComboBox 使用模板的具体方法

QComboBox 的常规使用方法,在这个使用模板里,基本都有了。 QComboBox小部件是一个组合的按钮和弹出列表。 QComboBox提供了一种向用户呈现选项列表的方式,其占用最小...

Python实现获取系统临时目录及临时文件的方法示例

本文实例讲述了Python实现获取系统临时目录及临时文件的方法。分享给大家供大家参考,具体如下: 在开发应用程序的过程中,会有一些临时的信息,或者不太重要的信息,会保存在一个特殊的目录下...