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

相关文章

Python3 文章标题关键字提取的例子

Python3 文章标题关键字提取的例子

思路: 1.读取所有文章标题; 2.用“结巴分词”的工具包进行文章标题的词语分割; 3.用“sklearn”的工具包计算Tf-idf(词频-逆文档率); 4.得到满足关键词权重阈值的词...

Python英文文本分词(无空格)模块wordninja的使用实例

在NLP中,数据清洗与分词往往是很多工作开始的第一步,大多数工作中只有中文语料数据需要进行分词,现有的分词工具也已经有了很多了,这里就不再多介绍了。英文语料由于其本身存在空格符所以无需跟...

详解Django-restframework 之频率源码分析

详解Django-restframework 之频率源码分析

一 前言 经过权限判断之后就是进行频率的判断了,而频率的判断和权限又不一样,认证、权限和频率的执行流程都差不多,使用配置里面的相关类来进行判断。而不和认证和权限一样,频率的配置没有,查看...

python3 中的字符串(单引号、双引号、三引号)以及字符串与数字的运算

python3中的字符串是一种常见的数据类型。 字符串有多种表现形式:单引号、双引号和三引号,且这些字符串的表现形式(单、双、三)都必须是成对出现的。 单、双引号是英文的:‘'和"",三...

有关wxpython pyqt内存占用问题分析

一直觉得wxpython占用内存比较多,在工作中写的一些小程序应用,一对比其它的小程序,发现内存相差确实有点大。 测试了下QT框架 复制代码 代码如下:import sys,timefr...