in reply to Perl Tk nonblocking
#!/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 | |
by tybalt89 (Monsignor) on Dec 01, 2016 at 03:14 UTC |