sashac88 has asked for the wisdom of the Perl Monks concerning the following question:

Hello great monsk!
I asked this question already and received a pretty cool
example from <zentara>. Below it is:
#!/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'); }
This works great. The only problem is that when I close the
widget, the prompt isn't returned. Does anyone know
how to overcome this?
Thanks a lot in advance!

Replies are listed 'Best First'.
Re: Adding the output of tailf -f filename to Tk widget (scrolled)
by kyle (Abbot) on Feb 26, 2007 at 19:04 UTC

    When Perl goes to close the $H handle, it will wait for the running command to finish. Because 'tail -f' never ends, it waits forever. I'd suggest using File::Tail here, but you could also kill the tail yourself. The call to open will return a PID that you can kill when MainLoop is finished.

    my $tail_pid = open($H,"tail -f -n 50 z.txt |") or die $!; # etc. MainLoop; kill 9, $tail_pid;