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

相关文章

完美解决python中ndarray 默认用科学计数法显示的问题

完美解决python中ndarray 默认用科学计数法显示的问题

机器环境: Python 3.6.4 numpy==1.14.0 pandas==0.22.0 解决方法: np.set_printoptions(suppress=True) 默认情况...

django创建最简单HTML页面跳转方法

假设已经通过: django-admin startproject +项目名称 python manage.py +项目应用 创建好一个项目以及内部的项目应用后,并且会运行django看...

python正常时间和unix时间戳相互转换的方法

本文实例讲述了python正常时间和unix时间戳相互转换的方法。分享给大家供大家参考。具体分析如下: 这段代码可以用来转换常规时间格式为unix时间戳,也可以将unix时间戳转换回来,...

python pygame实现滚动横版射击游戏城市之战

python pygame实现滚动横版射击游戏城市之战

pygame城市之战横版射击游戏,按上下左右方向箭头操作飞机。这是一个横板射击小游戏,在黑夜的城市上空,你将要操作一架飞机去射击敌机,爆炸效果还不错。 在游戏中定义了滚动的背景类,定义了...

Python实现识别手写数字 简易图片存储管理系统

Python实现识别手写数字 简易图片存储管理系统

写在前面 上一篇文章Python实现识别手写数字—图像的处理中我们讲了图片的处理,将图片经过剪裁,拉伸等操作以后将每一个图片变成了1x10000大小的向量。但是如果只是这样的话,我们每一...