Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Perl:TK - tail -f to text widget

by zentara (Archbishop)
on Aug 17, 2010 at 12:57 UTC ( [id://855489]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl:TK - tail -f to text widget
in thread Perl:TK - standard output to text widget

You are better off getting rid of the tie to STDOUT, that is a hack of last resort. :-)

Look at this. You could open multiple IPC connected filehandles, watch them with multiple fileevents, and insert the output into the same text widget, with different colored text.

#!/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-> Scrolled('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.
Old Perl Programmer Haiku

Replies are listed 'Best First'.
Re^4: Perl:TK - tail -f to text widget
by rehmanz (Novice) on Aug 17, 2010 at 20:11 UTC
    Thanks zentara! Worked to perfection....Here is my code that tails three separate files using the tabs....Cheers!
    use Tk; use Tk::NoteBook; use IO::Handle; my $S=IO::Handle->new; my $D=IO::Handle->new; my $E=IO::Handle->new; my $baseDir = "/"; my $sumFile = $baseDir."summary.log"; my $detFile = $baseDir."detail.log"; my $errFile = $baseDir."error.log"; open($S,"tail -f $sumFile |") or die $!; open($D,"tail -f $detFile |") or die $!; open($E,"tail -f $errFile |") or die $!; $mw = MainWindow->new(); $mw->geometry( "600x200" ); $book = $mw->NoteBook()->pack( -fill=>'both', -expand=>1 ); my $sumTab = $book->add( "Sheet 1", -bitmap => 'info'); my $detTab = $book->add( "Sheet 2", -bitmap => 'questhead'); my $errTab = $book->add( "Sheet 3", -bitmap => 'error'); my $sumText = $sumTab->Scrolled('Text', -wrap=>'none')->pack(-expand=> +1); my $detText = $detTab->Scrolled('Text', -wrap=>'none')->pack(-expand=> +1); my $errText = $errTab->Scrolled('Text', -wrap=>'none')->pack(-expand=> +1); $sumText->fileevent(\*$S,'readable',[\&fillSummary,$sumText]); $detText->fileevent(\*$D,'readable',[\&fillDetails,$detText]); $errText->fileevent(\*$E,'readable',[\&fillErrors,$errText]); MainLoop; sub fillSummary { my ($w) = @_; my $text = <$S>; $w->insert('end',$text); $w->yview('end'); } sub fillDetails { my ($w) = @_; my $text = <$D>; $w->insert('end',$text); $w->yview('end'); } sub fillErrors { my ($w) = @_; my $text = <$E>; $w->insert('end',$text); $w->yview('end'); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://855489]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found