Quote:
> > I'm looking for a way to grab the output from the UNIX command
> > 'tail -f <filename>', displaying the output in a text frame.
> > Simply exec'ing the command does not do the trick; only one line is
> > displayed and subsequent writing to the file does not show up. It would
> > seem I need to somehow actively poll for new lines written to the file,
> > maybe?
> > Has anyone done something like this before? I would appreciate any
> > pointers. Thanks,
> > Tom
> Of course, you don't need to use tail -f to do this, but ...
> #
> # tail -f a file into a text widget
> #
> proc tail-f {w file} {
> set fp [open "| tail -f $file" r]
> fconfigure $fp -blocking false
> fileevent $fp readable [list tail-f-progress $w $fp]
> }
> proc tail-f-progress {w fp} {
> if {[eof $fp]} {
> if {[catch {close $fp} error]} {
> $w insert end $error
> }
> $w insert end "Finished\n"
> } else {
> $w insert end [read $fp]
> }
> }
Your implementation of tail -f is not quite right. I believe that once
you reach the end of the file and have closed it you have to keep polling
the size until it changes, reopen it, move to the end of the data you
have read and then repeat this.