0

I am trying to grab the output of a log file that is constantly being written to. I have tried several different methods and all of them return the same result of nothing showing up.

The current code reads:

threads[threadName] = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
print "Thread: " + threadName
for line in threads[threadName].stdout:
        print line

Let's say cmd = tail -F /home/log.log | egrep "it worked!"

I want to constantly read the log file looking for it worked! to pop up.

hichris123
  • 9,735
  • 15
  • 51
  • 66
Demonicpenguin
  • 113
  • 2
  • 13
  • I see several issues . You could fix some of them using [this answer](http://stackoverflow.com/a/17698359/4279) (pass `--line-buffered` to `grep`, use `iter()` to workaround the read-ahead bug, add [`softspace`](https://docs.python.org/2.7/library/stdtypes.html#file.softspace) comma at the end of `print` statement)—apply the solution and update your question with a new code and the description of the remaining issues (what do you expect to happen? What happens instead? describe step by step). – jfs Apr 26 '16 at 18:44
  • related: [`pygtail`](https://github.com/bgreenlee/pygtail) – jfs Apr 26 '16 at 18:48

0 Answers0