Python:如何得到Popen的输出?

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-17 04:09   23   0

最近在用subprocess中的Popen做个磁盘监控小程序,但是在使用ps = Popen("df -h", shell=True, stdout=PIPE, stderr=PIPE)之后,再使用output_lines = ps.stdout.readlines()的时候,output_lines总是内容为空,有哪位知道是什么原因么?

btw:我是在windows下设计这个程序的

ExpandedBlockStart.gif 代码
# !/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


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP