exec

execPATHNAMELISTexecLIST
The exec function terminates the current program and executes an external
command and never returns!!! Use system instead of exec to return to your program after the
commands complete. The exec function
fails and returns false only if the command does not exist
and if it is executed directly instead of via your
system’s command shell, discussed below.
If there is only one scalar argument, the argument is checked for shell metacharacters. If metacharacters are found, the entire argument is passed to the system’s standard command interpreter (/bin/sh under Unix). If there are no metacharacters, the argument is split into words and executed directly, since in the interests of efficiency this bypasses the overhead of shell processing. It also gives you more control of error recovery should the program not exist.
If there is more than one argument in
LIST, or if LIST
is an array with more than one value, the system shell will never be
used. This also bypasses any shell processing of the command. The
presence or absence of metacharacters in the arguments doesn’t affect
this list-triggered behavior, which makes it the preferred form in
security-conscious programs that do not wish to expose themselves to
injection attacks via shell escapes.
This example causes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access