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写日志文件操作类与应用示例

本文实例讲述了python写日志文件操作类与应用。分享给大家供大家参考,具体如下: 项目的开发过程中,日志文件是少不了的,通过写日志文件,可以知道程序运行的情况。特别当部署在生产环境中的...

Python之web模板应用

Python的web模板,其实就是在HTML文档中使用控制语句和表达语句替换HTML文档中的变量来控制HTML的显示格式,Python的web模板可以更加灵活和方便的控制HTML的显示,...

python 统计一个列表当中的每一个元素出现了多少次的方法

如下所示: #coding=utf-8 #方式一 print('*'*20 + '方式一' + '*'*20) li1 = [1,2,2,3,3,3,4,4,4,4,5,5,5,5,...

python生成多个只含0,1元素的随机数组或列表的实例

如下所示: >>> import numpy as np >>> myarray= np.random.randint(0,2,10)输出只含0,...

详解python校验SQL脚本命名规则

详解python校验SQL脚本命名规则

需求背景 检查脚本文件中SQL语句是否按规范编写,规则如下: 创建表时,表名称需以"t_"开头且均为小写 增加和创建列时,列名称均为小写字母和_组成 创建函数,函数名称需以...