Are there any best practices for securely passing parameters from PHP to a CMD file?

When passing parameters from PHP to a CMD file, it is important to properly escape and sanitize the input to prevent any potential security vulnerabilities such as command injection attacks. One way to securely pass parameters is to use escapeshellarg() function in PHP to properly escape the parameter values before passing them to the CMD file.

$param1 = escapeshellarg($param1);
$param2 = escapeshellarg($param2);

// Execute the CMD file with the securely escaped parameters
exec('your_cmd_file.bat '.$param1.' '.$param2);