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

Is this documented anywhere?

The sources (win32/win32.c terminate_process()) is the only place I know of.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re^3: How do I cleanly kill a spawned process on Win32.

Replies are listed 'Best First'.
Re^4: How do I cleanly kill a spawned process on Win32.
by Anonymous Monk on Apr 20, 2009 at 02:22 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; } } }