Exec:
- exec — Execute an external program
Description:
exec() executes the given command.
Example #1
[ad type=”banner”]shell_exec
- shell_exec — Execute command via shell and return the complete output as a string
Description:
This function is identical to the backtick operator.
Example #2 :
A couple of distinctions that weren’t touched on here:
- With this function, you can pass an optional param variable which will receive an array of output lines. In some cases this might save time, especially if the output of the commands is already tabular.
Compare:
[ad type=”banner”]- Conversely, if the output of the command is xml or json, then having each line as part of an array is not what you want, as you’ll need to post-process the input into some other form, so in that case use shell_exec.
- It’s also worth pointing out that shell_exec is an alias for the backtick operator, for those used to *nix.
- It also supports an additional parameter that will provide the return code from the executed command:
As noted in the shell_exec manual page, when you actually require a return code from the command being executed, you have no choice but to use exec.
Difference:
- shell_exec – Execute command via shell and return the complete output as a string
- exec – Execute an external program.
The difference is that with shell_exec you get output as a return value.