我想完成一個想法,我真的不知道該怎麼做。基本上我試圖捕捉通過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