in reply to Tk GUI and Listen?

I don't use windows, but this works very fast, and uses low cpu. It requires that you have a version of tail that works on windows, you can groups.google.com for "tail for windows".

Just run this as your "capture" script.

#!/usr/bin/perl use strict; use Tk; use IO::Handle; my $H=IO::Handle->new; open($H,"tail -f -n 1 test.dat |") or die $!; my $main = MainWindow->new; my $t = $main->Text( -wrap=>'none', -height => 2, )->pack(-expand=>1); $main->fileevent(\*$H,'readable',[\&fill,$t]); MainLoop; sub fill { my ($w) = @_; my $text; my $text =<$H>; $w->delete('0.0','end'); $w->insert('end',$text); $w->yview('end'); }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: Tk GUI and Listen?
by Anonymous Monk on Oct 27, 2006 at 14:29 UTC
    That might work...but the fill method never seems to get called?
      Oh yeah, you have a windows version that dosn't like tk's fileevent method. Some windows versions can use it, others can't. In that case, instead of a fileevent, you can setup a timer to do the read. You would need the timer to be faster than the log-line-writing speed, so you don't miss a line.

      But you are probably better off using the win32 modules that jdtoronto showed you. See Perl/Tk App and Interprocess Communication for a discussion. BrowserUk shows some nice threaded methods that work on win32.

      Also use the Search Box and search for "win32 tail" for some other ideas.


      I'm not really a human, but I play one on earth. Cogito ergo sum a bum
        Nice link...Definiteley helps. Thanks!