What are some potential pitfalls of using exec and passthru in PHP to open external applications?

Potential pitfalls of using exec and passthru in PHP to open external applications include security vulnerabilities such as command injection attacks and exposing sensitive information. To mitigate these risks, it is recommended to validate and sanitize user input before passing it to exec or passthru functions.

$user_input = $_GET['input']; // Assuming user input is being passed to exec or passthru

// Validate and sanitize user input before using it
$validated_input = escapeshellarg($user_input);

// Use the validated input in exec or passthru
exec("external_application " . $validated_input);