请教一个subprocess.Popen,执行tail -f xxx.log|grep "error"的问题
0
我的目的是想监控 /var/log/message中的error关键字,但是发现用tail -f |grep这种不起作用,打印不出来带有error的行。请大侠帮忙看看。
logname= '111.log'
command='tail -f '+logname+'|grep "error"'
popen=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
while True:
line=popen.stdout.readline().strip()
print line
logname= '111.log'
command='tail -f '+logname+'|grep "error"'
popen=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
while True:
line=popen.stdout.readline().strip()
print line
没有找到相关结果
重要提示:提问者不能发表回复,可以通过评论与回答者沟通,沟通后可以通过编辑功能完善问题描述,以便后续其他人能够更容易理解问题.
1 个回复
牟瑞 - 大数据 Hadoop 讲师 Hadoop入门课程地址:http://www.hellobi.com/course/39 有架构师,技术总监,CTO的职位请联系我! 2016-07-26 回答
赞同来自: