in reply to 'exec' & 'Location' problem

exec will never exit, this is the expected behaviour. There are many ways to execute external programs in perl.

Example 1:
#!/usr/bin/perl -w if (condition) { system '/usr/.../another.pl'; } print "Location: http://test/ \n\n";
Example 2:
#!/usr/bin/perl -w if (condition) { `/usr/.../another.pl` # notice the use of the back quote. } print "Location: http://test/ \n\n";
There are other methods too, like using Apache mod_perl's spawn_sub_process, etc.

Replies are listed 'Best First'.
Re: 'exec' & 'Location' problem
by Abigail-II (Bishop) on Sep 12, 2003 at 10:37 UTC
    exec will never exit

    That's not quite true. The manual page says:

    exec PROGRAM LIST 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 exe- cuted directly instead of via your system's com- mand shell (see below).

    It can fail, but that's an exception.

    Abigail

      Thanks Abi for pointing out that exec will return false upon error. I assumed too much and overlooked the fact that the external program might not exist.
Re: Re: 'exec' & 'Location' problem
by hmerrill (Friar) on Sep 12, 2003 at 12:44 UTC
    Be sure to read the perldocs on the 'system' and backticks commands:
    perldoc -q backticks perldoc -q system perldoc -f system
    so that you're aware of all the implications - security and otherwise. If you use 'system', be aware that system does give back a return code, and, there is a 'more right' way to execute 'system' (and backticks) so that the shell is not involved.

    HTH.