python 捕获 shell/bash 脚本的输出结果实例

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

相关文章

解决python3 安装不了PIL的问题

解决python3 安装不了PIL的问题

python3无法正常安装PIL,因为PIL只支持python2各个版本,还没有python3的版本。 这里是PIL官网http://www.pythonware.com/product...

Django密码系统实现过程详解

一、Django密码存储和加密方式 #算法+迭代+盐+加密 <algorithm>$<iterations>$<salt>$<hash>...

python定时检查启动某个exe程序适合检测exe是否挂了

详见代码如下: 复制代码 代码如下: import threading import time import os import subprocess def get_process_c...

关于Numpy数据类型对象(dtype)使用详解

常用方法 #记住引入numpy时要是用别名np,则所有的numpy字样都要替换 #查询数值类型 >>>type(float) dtype('float64') #...

python 列表中[ ]中冒号‘:’的作用

中括号[ ]:用于定义列表或引用列表、数组、字符串及元组中元素位置 list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1,...