Perl exec Function

Advertisements


Description

This function executes a system command (directly, not within a shell) and never returns to the calling script, except if the command specified does not exist and has been called directly, instead of indirectly through a shell. The operation works as follows:

If there is only one scalar argument that contains no shell metacharacters, then the argument is converted into a list and the command is executed directly, without a shell.

If there is only one scalar argument that contains shell metacharacters, then the argument is executed through the standard shell, usually /bin/sh on Unix.

If LIST is more than one argument, or an array with more than one value, then the command is executed directly without the use of a shell.

Syntax

Following is the simple syntax for this function:

exec EXPR LIST

exec LIST

Return Value

This function returns 0 only if the command specified cannot be executed.

Example

Following is the example code showing its basic usage:


When above code is executed, it produced following result:




Advertisements
Advertisements