in reply to Adding the output of tailf -f filename to Tk widget (scrolled)

There are a few variations on this, but basically you do a piped-open of the tail command, then run the filehandle thru Tk::fileeevnt. But here is an even easier way.
#!/usr/bin/perl use strict; use Tk; use IO::Handle; my $H=IO::Handle->new; open($H,"tail -f -n 50 z.txt |") or die $!; my $main = MainWindow->new; my $t=$main->Text(-wrap=>'none')->pack(-expand=>1); $main->fileevent(\*$H,'readable',[\&fill,$t]); MainLoop; sub fill { my ($w)=@_; my $text; my $text =<$H>; $w->insert('end',$text); $w->yview('end'); }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum
  • Comment on Re: Adding the output of tailf -f filename to Tk widget (scrolled)
  • Download Code