Вы будете иметь намного больше контроля, используя функцию PHP proc_open. Это позволяет вам писать / читать стандартный ввод / вывод очень контролируемым образом:
$tunnels=array(
0 => array('pipe','r'), // Process std input
1 => array('pipe','w'), // Process std output
2 => array('pipe','w') // Process std error
);
$io=array();
$resource=proc_open("command with parameters...etc",$tunnels,$io);
if(!is_resource($resource)) {
// Throw exception or something...
}
// Write to process standard input and close stream
fwrite($io[0],"Some data...");
fclose($io[0]);
// We are not interested in process standard output.. close it
fclose($io[1]);
// Get process std error
$errors=stream_get_contents($io[2]);
fclose($io[2]);
// Close process reousrce
$result=proc_close($resource);
if($result != 0) {
// There where errors. Grab the error string from $errors
}