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.


In reply to Win32::CreateProcess problem by mdamazon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.