http://qs1969.pair.com?node_id=226570


in reply to How to kill an external program

The following code works for me. It assumes the process returns before it's done (I think all Win32 GUI programs do that, but command line ones don't - which sort are you using?).

my $PID = open my($Notepad), "|notepad.exe"; sleep 1; print "DIE!\n"; kill 9, $PID;

Perl Monks do it more than one way.

Replies are listed 'Best First'.
Re: How to kill an external program
by Anonymous Monk on Jan 13, 2003 at 22:03 UTC
    Thank you so much for your replies. I finally got it working with the Win32::Process. Here is what I came up with… Thanks again
    my $tempSleepMilSec = ($tempSleepSec * 1000); # amt of time to wait Win32::Process::Create($spiderProc, 'k:\\...\\spider.exe', "", 0, DETACHED_PROCESS, ".") || die ("can't create process: $!"); if ($spiderProc->Wait($tempSleepMilSec)) { print ("finished fine"); } else { print ("too long - killing"); my $tempKill = $spiderProc->Kill(0); }