What are the potential pitfalls of using exec() to call a PHP script from another PHP script?

Using exec() to call a PHP script from another PHP script can be risky as it opens up the possibility of command injection attacks if the input is not properly sanitized. To mitigate this risk, it is recommended to use escapeshellarg() or escapeshellcmd() to sanitize any user input before passing it to exec().

$script = 'path/to/script.php';
$input = $_POST['input']; // User input that needs to be sanitized

// Sanitize user input before passing it to exec()
$input = escapeshellarg($input);

// Call the PHP script using exec()
exec("php $script $input");