Это должно быть довольно просто. Все, что вам нужно, это убедиться, что вы не вставляете в скрипт странные данные, чтобы избежать каких-либо разрывов, и перенаправить STDERR в STDOUT, чтобы избежать ошибок и невозможности их увидеть.
<?php
// configuration
$scriptName = 'foo.exe';
// sets the header to send raw data to the browser
header('Content-Type: text/plain');
// disables the timeout for your script
set_time_limit(0);
// if the input is not an integer
if (! is_integer($_GET['id']))
{
// throw to forbidden page
header("HTTP/1.0 403 Forbidden");
die();
}
// parameter to use as parameter of
// the command to call
$parameterId = (int) $_GET['id'];
// preparing the command and redirecting STDERR to STDOUT (the browser)
$command = "$scriptName $parameterId 2>&1";
// executing command and outputing it
print(shell_exec($command));
Надеюсь, это поможет!