While playing around, I've noticed some peculiarities with Tk::fileevent. If it's something with alot of output, you may need to throttle it a little bit. For instance, this first example will not produce output, but the second will. I need to study more on this. I believe it boils down to the filehandle needs to "be readable", it won't buffer for you.
The following will run#!/usr/bin/perl use warnings; use strict; use Tk; startpiper(); my $mw = new MainWindow; my $t = $mw->Scrolled("Text",-width => 80, -height => 25, -wrap => 'no +ne'); $t->pack(-expand => 1); $mw->fileevent(\*CHILD, 'readable', [\&fill_text_widget,$t]); MainLoop; sub fill_text_widget { my($widget) = @_; $_ = <CHILD>; $widget->insert('end', $_); $widget->yview('end'); } sub startpiper{ open(CHILD, "ls -la |") or die "Can't open: $!"; }
And the piper script#!/usr/bin/perl use warnings; use strict; use Tk; open(CHILD, "./fileevent2piper 2>&1 |") or die "Can't open: $!"; my $mw = new MainWindow; my $t = $mw->Scrolled("Text",-width => 80, -height => 25, -wrap => 'no +ne'); $t->pack(-expand => 1); $mw->fileevent(\*CHILD, 'readable', [\&fill_text_widget,$t]); MainLoop; sub fill_text_widget { my($widget) = @_; $_ = <CHILD>; $widget->insert('end', $_); $widget->yview('end'); }
#!/usr/bin/perl $|++; for my $i ( 0 .. 10) { print $i, "\n"; print `ls -la`; sleep 1; }
In reply to Re: Perl::TK - fileevent and script execution theory
by zentara
in thread Perl::TK - fileevent and script execution theory
by crabbdean
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |