in reply to Perl Tk nonblocking

fileevent worked for me. Just populate the widget from a fileevent handler:
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = 'MainWindow'->new(-title => 'nmap'); my $b1 = $mw->Button(-text => 'Go', -command => \&go)->pack; my $b2 = $mw->Button(-text => 'Exit', -command => \&Tk::exit)->pack; my $text = $mw->Scrolled('Text', -scrollbars => 'e')->pack; MainLoop(); sub go { open my $nmap, '-|', 'nmap -A localhost' or die $!; $text->fileevent($nmap, 'readable', sub { $text->insert(end => scalar <$nmap>); }); }

BTW, no need for sub {&go} etc. Lexical filehandles and 3-argument form of open exist for pipes, too.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Perl Tk nonblocking
by rjbuckley (Novice) on Nov 30, 2016 at 23:10 UTC

    Thanks Choroba, I tried your code and got the same result as when I attempted fileevent. After inserting the text, the gui freezes. Might be something about my build: Perl 5.022001 Tk 8.4 4.4.0-47-generic GNU/Linux Do you know anything about using pipes to get it done? Thanks, -rjb

      Note that a filehandle may be "readable", but not have a complete line. This may cause a "hang" when reading with angle brackets.