It sounds like you are trying to do something complicated. This link may help explain the basics of events TPJ article on events

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.

#!/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: $!"; }
The following will run
#!/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'); }
And the piper script
#!/usr/bin/perl $|++; for my $i ( 0 .. 10) { print $i, "\n"; print `ls -la`; sleep 1; }

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Perl::TK - fileevent and script execution theory by zentara
in thread Perl::TK - fileevent and script execution theory by crabbdean

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.