Python:如何得到Popen的输出?
from:http://www.cnblogs.com/bluescorpio/archive/2010/05/04/1727020.html
最近在用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
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
hadoop大数据相关
posted on 2015-02-10 22:14 浪子回头jin不换 阅读(1394) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步