0

我必须运行 Java 应用程序并读取 syslog 以触发其他一些基于 Python 的事件。

同时,我还需要将其转储并存储在所有 java 输出的 /var/tmp/log.log 中,但由于添加了新的 Python 事件控制器,/var/tmp/log.log我无法创建。知道我怎么还能做到吗?. 例如:java | python >> java logs as >> log.log for tail -f

之前:(工作)

$ java -cp /var/tmp/Audio.jar Main.Boot >> /var/tmp/log.log &
$ tail -f /var/tmp/log.log

之后:(不工作)

$ java -cp /var/tmp/Audio.jar Main.Boot | python -u /var/tmp/consumer.py &
$ tail -f ????? how can i have the java syslog still dumped as like my BEFORE ????

/var/tmp/consumer.py

import sys, time, os
while True:
  line = sys.stdin.readline()
  if line:
    sys.stdout.flush()
    if "wall:on" in line:
      os.system("/var/tmp/me.sh")
  else:
    time.sleep(1)

/var/tmp/me.sh

#!/bin/bash
export DISPLAY=:0.0 
ps aux | grep "/var/tmp/pp.py" | awk '{print $2}' | xargs kill -9;
# System maintain..
python /var/tmp/pp.py &
sleep 3
ps aux | grep "/var/tmp/pp.py" | awk '{print $2}' | xargs kill -9;
4

1 回答 1

1

Off the top of my head:

$ java -cp /var/tmp/Audio.jar Main.Boot | tee /var/tmp/log.log | python -u /var/tmp/consumer.py &
$ tail -f /var/tmp/log.log

I would also do the awk/grep stuff inside python instead of going through a subprocess.

于 2013-08-03T02:39:04.813 回答