protected function runCommand($command, &$outputStr, &$errorStr, $inputStr = null)
{
$descriptors = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
$process = proc_open($command, $descriptors, $fd);
if (is_resource($process)) {
/* Write to input */
if ($inputStr !== null) {
fwrite($fd[0], $inputStr);
}
fclose($fd[0]);
/* Read stdout */
$outputStr = stream_get_contents($fd[1]);
fclose($fd[1]);
/* Read stderr */
$errorStr = stream_get_contents($fd[2]);
fclose($fd[2]);
/* Finish up */
$retval = proc_close($process);
return $retval;
} else {
/* Method calling this should notice a non-zero exit and print an error */
return -1;
}
}