Hello,
On Windows XP, I can use Win32::Process::Create to run whatever I want,
such as pop up Notepad (the standard example), call up Perl to run a .pl
file, etcetera. However, if I use it to run a pp created executable, I
cannot use the "known" way to kill the executable. The end goal here is
to be able to create a process, run the pp created executable in that
process, wait a specified time and then kill the created process if I
want to. I cannot kill the created process.
I create the executable with
C:\aaa>pp -o hello_print.exe hello_print.pl
An example of what works is below. When run from a command line, it
simply prints "Hello" forever in a loop:
-----------paste what works
C:\aaa>type hello_print.pl
#!/usr/bin/perl -w
# File hello_print.pl
use strict;
while (1) {
print "Hello\n";
sleep(1);
}
C:\aaa>type test_win32_process_create_04.pl
#!/usr/bin/perl -w
# File: test_win32_process_create_04.pl
if ($^O eq 'MSWin32') {
eval {
require Win32::Process;
Win32::Process->import;
}
}
use strict;
my $ProcessObj = "";
Win32::Process::Create(
$ProcessObj,
"C:/perl/bin/perl.exe",
"perl c:/aaa/hello_print.pl",
0,
Win32::Process->NORMAL_PRIORITY_CLASS,
".")|| die ("Cannot Win32::Process::Create:$!:\n");
$ProcessObj->Wait(2000);
my $pid = $ProcessObj-> GetProcessID();
print "About to kill pid $pid\n";
$ProcessObj->Kill($pid);
----------end paste what works
If I create a process that directly invokes a pp'd executable, I cannot
seem to kill it without doing Ctrl-C by hand.
-------------paste what will not get killed
#!/usr/bin/perl -w
# File: test_win32_process_create_05.pl
if ($^O eq 'MSWin32') {
eval {
require Win32::Process;
Win32::Process->import;
}
}
use strict;
my $ProcessObj = "";
Win32::Process::Create(
$ProcessObj,
"C:/aaa/hello_print.exe",
"hello_print.exe",
0,
Win32::Process->NORMAL_PRIORITY_CLASS, # I have
also tried CREATE_NEW_PROCESS_GROUP
".")|| die ("Cannot Win32::Process::Create:$!:\n");
$ProcessObj->Wait(2000);
my $pid = $ProcessObj-> GetProcessID();
print "About to kill pid $pid\n";
$ProcessObj->Kill($pid);
-------------end paste what will not get killed
According to the task manager, there are three process ids associated
with running test_win32_process_create_05.pl. One is perl, one is
test_win32_process_create_05.pl, and one is the created process that
will not kill, hello_print.exe.
I tried adding the paste below to hello_print.pl but it did not help.
#............. Play nice with the OS ..........
sub exit_signal {
my ($signal) = @_;
CORE::exit($signal);
}
$SIG{ABRT} = \&exit_signal;
$SIG{ALRM} = \&exit_signal;
$SIG{BREAK} = \&exit_signal;
$SIG{CLD} = \&exit_signal;
$SIG{FPE} = \&exit_signal;
$SIG{HUP} = \&exit_signal;
$SIG{ILL} = \&exit_signal;
$SIG{INT} = \&exit_signal;
$SIG{QUIT} = \&exit_signal;
$SIG{SEGV} = \&exit_signal;
$SIG{TERM} = \&exit_signal;
$SIG{__DIE__} = \&exit_signal;
#..............................................
Has anyone else run into this problem?
Thanks