I can execute Win32::CreateProcess in a loop succesfully. Now I want to prevent my script from moving forward until all the child processes that were created in the loop have exited. This is causing problems. The code inside the first foreach loop below executes properly. The code below inside the while loop which attempts to detect the status of the child processes is not.
use Win32::Process qw(CREATE_NEW_CONSOLE STILL_ACTIVE);
use Win32;
my %procs=();
foreach my $a (@array) {
my $cmd01 = 'some command ' . $a . ' other stuff';
my $cmd = "cmd /c echo Performing job. Please wait...
+& $cmd01";
my $ProcessObj;
Win32::Process::Create($ProcessObj,"C:\\WINDOWS\\syste
+m32\\cmd.exe","$cmd01",0,CREATE_NEW_CONSOLE,".");
$procs{$ProcessObj} = $a;
}
while (%procs) {
foreach my $key (keys %procs) {
my $exit_code = 1;
$key->GetExitCode($exit_code);
while($exit_code == Win32::Process::ST
+ILL_ACTIVE()) {
sleep(1);
$key->GetExitCode($exi
+t_code);
}
print "GetExitCode returned $exit_code
+, exiting main process for $procs{$key}.\n";
delete $procs{$key};
}
}
This returns:
Can't locate object method "GetExitCode" via package
"Win32::Process=SCALAR(0x6e604a4)" (perhaps you forgot to load "Win32::Process=SCALAR(0x6e604a4)"?) at ..\code\script.pl line 1498, <STDIN> line 1 (#1)
Uncaught exception from user code:
Can't locate object method "GetExitCode" via package "Win32::Process=SCALAR(0x6e604a4)" (perhaps you forgot to load "Win32::Process=SCALAR(0x6e604a4)"?) at ..\code\script.pl line 1498, <STDIN> line 1.