Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

exec

Replaces the current process image with a new program via execvp(3).

On success, exec does not return because the current process image is replaced entirely. If exec does return, it means the call failed, and the return value is false.

In the single-argument form, shell metacharacters trigger execution via /bin/sh -c. If no metacharacters are detected, the command is executed directly. In the multi-argument form, the first argument is the program and subsequent arguments are passed directly (no shell involvement).

The child inherits Perl’s %ENV (the OS environment is replaced before exec).

Synopsis

exec("ls -la");              # shell form
exec("ls", "-la");           # list form (no shell)
exec { "ls" } "ls", "-l";   # indirect object form

See Also

system, fork, exec