Python:如何得到Popen的输出?
2010-05-04 10:49
477 查看
最近在用subprocess中的Popen做个磁盘监控小程序,但是在使用ps = Popen("df -h", shell=True, stdout=PIPE, stderr=PIPE)之后,再使用output_lines = ps.stdout.readlines()的时候,output_lines总是内容为空,有哪位知道是什么原因么?
btw:我是在windows下设计这个程序的
代码#!/usr/bin/env python
#coding=utf-8
from subprocess import Popen, PIPE
import re
def disk_space(pattern="2[0-9]%", message="CAPACITY WARNING"):
## take shell command output
ps = Popen("df -h", shell=True, stdout=PIPE, stderr=PIPE)
output_lines = ps.stdout.readlines()
for line in output_lines:
line = line.strip()
if re.search(pattern, line):
print "%s %s" %(message, line)
if __name__ == '__main__':
disk_space
btw:我是在windows下设计这个程序的
代码#!/usr/bin/env python
#coding=utf-8
from subprocess import Popen, PIPE
import re
def disk_space(pattern="2[0-9]%", message="CAPACITY WARNING"):
## take shell command output
ps = Popen("df -h", shell=True, stdout=PIPE, stderr=PIPE)
output_lines = ps.stdout.readlines()
for line in output_lines:
line = line.strip()
if re.search(pattern, line):
print "%s %s" %(message, line)
if __name__ == '__main__':
disk_space
相关文章推荐
- Python:如何得到Popen的输出?
- SQLSERVER 存储过程调用存储过程,如何得到输出参数
- Python终端如何输出彩色字体
- Python DataFrame 如何设置输出不显示index(索引)值
- Python如何输出包含在对象中的中文字符?
- 如何用python快速得到文件夹下面的文件名和路径
- Python中如何输出完整的Exception Stack?
- python如何格式化输出百分号
- 在Python3中如何输出中文
- go和python调用其它程序并得到程序输出
- python输出htmltestrunner中文乱码如何解决
- 如何得到动态链接库的输出函数(delphi tdump.exe)
- MS的SQLHelper中如何得到存储过程的输出参数值
- CI框架如何把视图文件压缩输出,得到去除了空格注释的html代码
- python subprocess.Popen 监控控制台输出
- python——pandas--如何得到某一个值所在的行?
- 如何得到卷积层输出的深度--CNN卷积层
- 如何输出python中list的维度
- python中如何使输出不换行
- python如何得到13位时间戳?