How can output redirection be used effectively when executing external commands in PHP?
Output redirection can be used effectively when executing external commands in PHP by capturing the output of the command and storing it in a variable or a file. This can be useful for logging, debugging, or processing the output of the command further.
// Execute an external command and capture its output
$output = shell_exec('ls -la');
// Print the output
echo $output;