Comp.lang.tcl questioners frequently demand some sort of gadget to monitor-an-ongoing-process-and-display-the-result-in-a-text. Tailing widget is the simplest answer CL knows that meets the common intent of these requests.
There are lots of variations on this theme, though. tailf carefully implements the functionality of the Unix tail(1), and adds a bit of filtering capability. I've written a few examples [L1 ] that show how different combinations of IPC, fileevent, after, ... can co-operate to monitor continuing processes.
A utility to filter the output of tail is greptail. It lazily uses the unix tail(1) program.
Also see directory notification package in Tcl (Linux 2.4 and higher).
And a more generic approach is outlined on the file and directory change notifications page.
Here is another version. It continuously opens and closes the file and seems to work where a normal "tail -f" fails, because it has the file opened the whole time:
proc tail-f {filename} { # get an initial last position: set fh [open $filename r] seek $fh 0 end set pos [tell $fh] close $fh # ask again all second: while 1 { after 1000 set fh [open $filename r] fconfigure $fh -blocking no -buffering line seek $fh $pos start while {[eof $fh] == 0} { gets $fh line if {[string length $line] > 0} {puts $line} } set pos [tell $fh] close $fh } }
?? I don't understand; how (when, where) does "a normal 'tail -f' fail"? Do you have in mind the case where the underlying file is "rotated out", as logfiles are often maintained?