What are some best practices for handling output redirection in PHP when using exec?

When using the `exec` function in PHP to run external commands, it is important to properly handle output redirection to capture the command's output. One common approach is to use the `2>&1` syntax in the command string to redirect both standard output and standard error to the same stream. This allows you to capture both types of output for further processing or logging.

// Command to be executed
$command = 'your_command 2>&1';

// Execute the command and capture the output
$output = [];
exec($command, $output);

// Output the captured output
foreach ($output as $line) {
    echo $line . "<br>";
}