A very handy tool in the UNIX world is tail. In particular the option -F proves useful if you want to view log files. But what do you do if you’re working with Windows? Of course, you have to search the Internet for a Windows port and go through the compile-hell. I have to admit, compiling tail wouldn’t be such a pain in the ass as compiler bigger programs. Nonetheless, I wasn’t willing to spend time searching and installing a Windows port of tail and thus I coded it within a couple of minutes. The following Python script only implements tail -F filename, but that was sufficient for my purposes.
import sys, time
lastLine = 0
f = 0
def dumpFile(f, start):
f.seek(start)
cur = start
for line in f:
print line,
cur = f.tell()
return cur
while True:
try:
f = open(sys.argv[1], 'rU')
lastLine = dumpFile(f, lastLine)
time.sleep(1.5)
except IOError:
print 'no such file' + sys.argv[1]
finally:
if f:
f.close
Comments