in reply to Re^2: multi-command sytem call
in thread multi-command sytem call

exec does not fork, it overwrites the current process. It doesn't return, unless something goes wrong, because there's nothing to return to, nor record that it should even try.

--
I'm not belgian but I play one on TV.

Replies are listed 'Best First'.
Re^4: multi-command sytem call
by Elijah (Hermit) on Aug 25, 2004 at 15:48 UTC
    I am sorry, yes you are right. Maybe "fork" was a bad word to use here. By it's very nature a forked process runs but the parent process continues to run also. The exec() function does overwrite the current process and is apparent in some simple code such as the following:
    #!/usr/bin/perl -w use strict; my $results = exec("lt", "-al", "."); print <<END; ########################### \$results \= $results ########################### END
    In the above example you will actually see the printed statement appear on the screen following an error message saying that the command "lt" does not exist. When the command or target program does not exist, or the call fails for any other reson is the only time you will get a "return" from exec().
    #!/usr/bin/perl -w use strict; my $results = exec("ls", "-al", "."); print <<END; ########################### \$results \= $results ########################### END
    Now this code will perform the list (ls) command on a *nix system feeding it "-al" as command line arguiments and "." (current dir) as the target to list. That is all the will appear on the screen and the following print statement will never be executed because the exec() function was successfull and overwrote this current process.

    Sorry for any confusion.


    www.perlskripts.com