in reply to parent not waiting for child process

The following seems to work for me... the test.bat script simply contains echo "inside batch script":

Update: added wait() call and associated output. Note that without wait(), child procs could become zombies. The call to wait() can be at the very bottom of the script, inside of a parent block.

use warnings; use strict; my $pid = fork(); if ($pid){ print "parent...\n"; } else { sleep 2; system "test.bat"; } if ($pid){ print "parent: doing stuff...\n"; } else { print "child: exiting\n"; } if ($pid){ print "parent: done doing stuff, waiting...\n"; wait; print "parent: children dead, safe to exit\n"; }

Output:

parent: doing stuff parent: done doing stuff, waiting... "inside batch script" child: exiting parent: children dead, safe to exit

Replies are listed 'Best First'.
Re^2: parent not waiting for child process
by BrowserUk (Patriarch) on Aug 02, 2016 at 19:15 UTC

    Using fork emulation on windows is just asking for trouble.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.