我想完成一个想法,我真的不知道该怎么做。基本上我试图捕捉通过grep命令的值如下所示处理access_log与子流程的实时输出
p = subprocess.Popen('tail -f /data/qantasflight/run/tomcat/logs/localhost_access_log.2016-02-29.txt | grep /qantas-ui/int/price?', stdout=subprocess.PIPE, shell = True)
stdout = p.communicate()[0]
过程中的标准输出值,然后按下值如下所示
f = urllib.urlopen("http://162.16.1.90:9140/TxnService", params2)
param2的是值,其中i将处理结果由subprocess.Popen
给出简而言之我想以下:
- 等待新值 - > - 过程的值 - > - 推值 - >
这应该是实时的,python脚本将继续获取新值,处理它,然后推送该值。
1-为什么在这里使用外部进程,如'tail','grep'(特别是'grep')? 2相关:[Python:从subprocess.communicate()读取流输入)(http://stackoverflow.com/q/2715847/4279) – jfs
为了澄清,你可以使用像'if'/ qantas-ui/int /价格':'代替'grep'在这里。 'tail -f'可以替换为''watchdog'包('$ pip install watchdog')](http://pythonhosted.org/watchdog/quickstart.html),虽然调用'tail -f'可能会更简单。 – jfs