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中的strftime()方法的使用

 strftime()方法转换成一个元组或struct_time表示时间所指定的格式参数所返回gmtime()或localtime()为一个字符串。 当t不设置,所返回当前时间...

使用Python获取CPU、内存和硬盘等windowns系统信息的2个例子

例子一: Python用WMI模块获取windowns系统的硬件信息:硬盘分区、使用情况,内存大小,CPU型号,当前运行的进程,自启动程序及位置,系统的版本等信息。 复制代码 代码如下:...

Python PIL图片添加字体的例子

Python PIL图片添加字体的例子

效果 左边原图,右面添加字体后保存的图。 代码 # -*- coding: utf-8 -*- import PIL.Image as Image import PIL.Image...

PyCharm的设置方法和第一个Python程序的建立

PyCharm的设置方法和第一个Python程序的建立

1.代码编辑 字体大小设置 进入 File—》Settings—》Editor—》Colors & Fonts—》Font中。 首先要点击“Save as”然后为这个设置命名,我这里填入...