Just use tail . He knows more that you are on how to handle complex cases (you can look at its source).
In one of my projects, I have something like this in order to track the trace file created by the proprietary tool:
set fd [open [list | tail --follow=name --retry --lines 0 $opt(trace) 2>@1]] chan event $fd readable [list FollowTrace $fd] proc FollowTrace fd { if {[gets $fd line] < 0} { set code [catch {close $fd} err] if {$code == 0} { set ::result 0 } else { puts stderr $err set ::result 1 } return } switch -regexp -matchvar parts -- $line { {Tm_Session::Open.*FileName=([^,]+)} { TryMakeLock [FullPathname [lindex $parts 1]] } {Tm_Session::Close.*FileName=([^,]+)} { StartUpload [lindex $parts 1] } } }
The general idea is that you create tail in the given file, then enter the event loop and tail process output line by line.
source share