Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Perl Tk nonblocking

by choroba (Cardinal)
on Nov 30, 2016 at 22:55 UTC ( [id://1176995]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1176995]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found