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

I'm a little confused when looking at the output from this sample perl code. Why doesn't child process print any output after completing the exec command?
Thanks for help, Matt

#!/usr/bin/perl $pid=fork(); if ($pid) { print "Returned from fork $pid \n"; print "Parent process id $$ \n"; } else { exec("./a.out"); print "Something \n"; }

Replies are listed 'Best First'.
Re: Output of a forked process
by zigster (Hermit) on Apr 24, 2001 at 16:42 UTC
    exec does not work like that, you want system

    Quote from exec
    The exec() function executes a system command AND NEVER RETURNS - use system() instead of exec() if you want it to return. It fails and returns FALSE only if the command does not exist and it is executed directly instead of via your system's command shell (see below).

    Have a look at exec more details are there.