I want to start a background process to tail a file, then read from the output so far on demand, while continuing to tail the file. I've tried a few things using subprocess
but haven't been able to make it work.
Here's what I tried:
tail = subprocess.Popen(['tail', '-f', 'file.txt'], stdout=subprocess.PIPE)
reader = tail.stdout
#do stuff
output = reader.read() #spins
I considered using reader.readline()
manually, but I can't figure out how to terminate the loop, since there won't be an EOF.