It seems fileevent is broken. Maybe current hardware can read much faster than when Tk was originally designed, so Tk can't manage to update before next line comes in?

Fortunately, you can use repeat to read the data from the process:

#! /usr/bin/perl use strict; use warnings; use Tk; { my $in; sub stop { undef $in } sub run { my ($type, $entry) = @_; my $command = $entry->cget('-text'); if (1 == $type) { my $out = $_[2]; open $in, '-|', $command or die $!; my $repeat; $repeat = ($entry->repeat(1, sub { return $entry->afterCancel($repeat) if $repeat && ! defined $in; read $in, my $buff, 100; if (length $buff) { $out->insert(end => $buff); $out->yview('end'); } })); } elsif (2 == $type) { system "$command&"; } } } my $mw = MainWindow->new(-title => 'Two background processes'); my $le_read_from = $mw->LabEntry(-label => 'Read from:', -labelPack => [qw[ -side left ]], -text => 'find')->pack; my $le_process = $mw->LabEntry(-label => 'Run in the background:', -labelPack => [qw[ -side left ]], -text => 'xterm')->pack; my $out; my $f_b = $mw->Frame->pack; my $b_run1 = $f_b->Button(-text => 'Run 1', -command => sub { run(1, $le_read_from, $out +) }) ->pack(-side => 'left'); my $b_run2 = $f_b->Button(-text => 'Run 2', -command => [\&run, 2, $le_process]) ->pack; my $f_b2 = $mw->Frame->pack; my $b_clear1 = $f_b2->Button(-text => 'Clear', -command => sub { $out->delete('0.0', 'en +d') }) ->pack(-side => 'left'); my $b_stop = $f_b2->Button(-text => 'Stop', -command => \&stop)->pack(-side => 'left'); my $b_quit = $f_b2->Button(-text => 'Quit', -command => sub { Tk::exit })->pack; my $playground = $mw->Text->pack; $playground->insert('0.0', "You can type any text here to check the interactivity.\n"); $out = $mw->ROText->pack; MainLoop();

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re: Second background process is pausing the gui by choroba
in thread Second background process is pausing the gui by Ohad

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.