The kill method does not send signals on windows. See http://perldoc.perl.org/perlport.html. I spent a long time determining how to start a process on windows and then send a ctrl-c "signal". The secret is perl shares the console with the application that was started. Enjoy!
#!/usr/bin/perl
use strict;
use warnings;
use Win32;
use Win32::Process;
use Win32::Process 'STILL_ACTIVE';
use Win32::Process::Info qw{NT};
use Win32::Console;
my $exe = $ARGV[0];
my $params = $ARGV[1];
my $appWorkingDir = $ARGV[2];
my $signalPollIntervalMillisec = $ARGV[3];
my $signalKillFile = $ARGV[4];
my $signalShutdownFile = $ARGV[5];
# Never die, only when child process terminates
$SIG{INT} = 'IGNORE';
$SIG{TERM} = 'IGNORE';
my $ProcessObj;
my $success = Win32::Process::Create($ProcessObj,$exe,$params,0,NORMAL
+_PRIORITY_CLASS,$appWorkingDir);
if ( $success ) {
my $pid = $ProcessObj->GetProcessID();
while ( 'true' ) {
$ProcessObj->Wait($signalPollIntervalMillisec);
$ProcessObj->GetExitCode($exitcode);
if ( $exitcode == STILL_ACTIVE ) {
# Take action base on some flag
if ( -e $signalKillFile ) {
kill -9, $pid;
exit -3;
} elsif ( -e $signalShutdownFile ) {
my $CONSOLE = Win32::Console->new();
$CONSOLE->GenerateCtrlEvent(CTRL_C_EVENT);
}
} else {
# Process terminated on it's own
exit $exitcode;
}
}
}
|