smudge has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use win32::process:create to run another program. I am using $proc->Wait(INFINITE) to wait for this new process to complete. The problem is that the created process forks another process and terminates, and then my perl program continues. I need to wait on the new child process as well. In case my description wasn't clear, here is what's happening:
perl program A create process B A waits on B B creates a process C B terminates A continues (but I want it to wait on C now!)
Note: B and C are commerical applications that I am unable to make changes to. Thanks!

Replies are listed 'Best First'.
Re: win32::process::create with multiple children
by pg (Canon) on Aug 31, 2005 at 02:56 UTC

    Win32::Process::Info can help in this case. The result is an AoH. Each hash contains info of a process. There are lots of information, and those three pieces are particually helpful to you: ProcessId, ParentProcessId and CommandLine (or Caption). You can find the child process's processid either base on CommandLine/Caption or ParentProcessId.

    use Win32::Process::Info; use Win32::Process; use Data::Dumper; use strict; use warnings; my $pi = Win32::Process::Info->new(); my @info = $pi->GetProcInfo (); print Dumper(\@info);
Re: win32::process::create with multiple children
by Anonymous Monk on Aug 31, 2005 at 12:26 UTC
    Hi,

    spawn processes with Win32::Job instead .

    It gives you job environement which is the corect way to manage subprocesses in windows. It's only with perl 5.8 tho

Re: win32::process::create with multiple children
by ikegami (Patriarch) on Aug 31, 2005 at 04:29 UTC

    If B can somehow communicates C's PID (returned by $ProcessObj->GetProcessID()) to A, A can use waitpid.

    Update: oops, scratch that. waitpid waits for a child process to terminate. Sorry, it's late.