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

After trial/error, I'm very very close. I'm capturing the subprocess ID with the following:
$sub_pid= open $pipe, "-|", "${tab}_${date}.sh 2>&1" or die "Can't exe +cute $tab : $!\n";
then kill the process with:
my $button = $popup->Button( -text => 'Kill', -command => [sub{`kill $sub_pid 2>&1` && warn "Can't kill subpro +cess: $sub_pid\n"}],-background=>'slate grey'); $button->pack;
Unfortunately $sub_pid returns 10523 rather than 10524. ps shows:
PID TTY TIME CMD
10514 pts/6 00:00:00 tools_generic.p
10523 pts/6 00:00:00 program1_125919
10524 pts/6 00:00:00 program1
10525 pts/6 00:00:00 ps
26437 pts/6 00:00:00 bas

I suppose this is a sub launching a sub? Therefore I must use KillFam?

So close!
honyok

Replies are listed 'Best First'.
Re^3: Tk Form GUI / external process error
by zentara (Cardinal) on Mar 26, 2009 at 20:16 UTC
    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
      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