in reply to Re: How do I cleanly kill a spawned process on Win32.
in thread How do I cleanly kill a spawned process on Win32.

Ha. That's exactly what I thought I saw from poking through Perl's source code. Is this documented anywhere?

FWIW, the server I'm testing already has a SetConsoleCtrlHandler defined, which is why I started this whole exercise in the first place.

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

  • Comment on Re^2: How do I cleanly kill a spawned process on Win32.

Replies are listed 'Best First'.
Re^3: How do I cleanly kill a spawned process on Win32.
by BrowserUk (Patriarch) on Feb 26, 2009 at 10:50 UTC
      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; } } }