python 服务日志监控 tail -f
elixu 2013-11-16 03:41:41 import subprocess
#path & name of log
filename = '/home/eli/codebase/refactor/api-server/log/online-config-development.log'
#shell command to be executed
command = 'tail -f '+filename+' | grep '+'groupcast'
popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print(command)
while True:
#get the content which the grep command get
print(popen.stdout.readline().strip())
执行之后就是打印不出来结果, 但是我直接在shell中输入打印的command就有结果。
python高手帮忙看下问题。