in reply to Re^2: Tk Form GUI / external process error
in thread Tk Form GUI / external process error

Here is an example. Some commands need IPC::Open3, and you do "my $pid = open3(.....)
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(-background => 'gray50'); my $text = $mw->Scrolled('Text')->pack(); my $pid; my $startb = $mw->Button( -text => 'Start', -command=> \&work, )->pack(); my $count = 0; my $label = $mw->Label(-textvariable=>\$count)->pack(); my $testtimer = $mw->repeat(500, sub { $count++} ); my $stopb = $mw->Button( -text => 'Exit', -command=>sub{ kill 9,$pid; exit; }, )->pack(); MainLoop; ##################################### sub work{ $startb->configure(-state=>'disabled'); use Fcntl; + my $flags; + #long 10 second delay between outputs $pid = open (my $fh, "top -b -d 10 |" ) or warn "$!\n"; fcntl($fh, F_SETFL, O_NONBLOCK) || die "$!\n"; # Set the non-block f +lags my $repeater; $repeater = $mw->repeat(10, sub { if(my $bytes = sysread( $fh, my $buf, 1024)){; $text->insert('end',$buf); $text->see('end'); } } ); }

P.S. Hurry with your questions, I won't be here for long...:-)


I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness

Replies are listed 'Best First'.
Re^4: Tk Form GUI / external process error
by honyok (Sexton) on Mar 27, 2009 at 14:08 UTC
    Thanks! Unfortunately I don't have administrative rights on the system, so I have to request new package installs from IT. I'll let you know if I get this resolved soon.
    Is there some install command which loads bundles of commonly used packages??
      I think Proc::KillFam is part of core Perl. IPC::Open3 is. There are many Tk-IPC::Open3 examples on google. If worse comes to worse, you can get the pid by running ps and grepping for it's script name. There are many ways to get pid, ....study harder grasshopper. :-)

      I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness