* clear the process environment and set LANG properly so we get english error codes and still keep utf8 compliant

* rename _read to _readStdout and introduce a generic _readStderr which reads from the other pipe on failure
This commit is contained in:
Thomas Keller 2010-06-24 00:10:41 +02:00
parent e57fc18bcb
commit 5ce324f35f

View File

@ -81,7 +81,10 @@ class IDF_Scm_Monotone_Stdio
2 => array("pipe", "w"), 2 => array("pipe", "w"),
); );
$this->proc = proc_open($cmd, $descriptors, $this->pipes); $env = array("LANG" => "en_US.UTF-8");
$this->proc = proc_open($cmd, $descriptors, $this->pipes,
null, $env);
if (!is_resource($this->proc)) if (!is_resource($this->proc))
{ {
@ -153,9 +156,9 @@ class IDF_Scm_Monotone_Stdio
$version = fgets($this->pipes[1]); $version = fgets($this->pipes[1]);
if ($version === false) if ($version === false)
{ {
$err = fgets($this->pipes[2]);
throw new IDF_Scm_Exception( throw new IDF_Scm_Exception(
"Could not determine stdio version: $err" "Could not determine stdio version, stderr is:\n".
$this->_readStderr()
); );
} }
@ -214,13 +217,28 @@ class IDF_Scm_Monotone_Stdio
$this->cmdnum++; $this->cmdnum++;
} }
/**
* Reads all output from stderr and returns it
*
* @return string
*/
private function _readStderr()
{
$err = "";
while (($line = fgets($this->pipes[2])) !== false)
{
$err .= $line;
}
return empty($err) ? "<empty>" : $err;
}
/** /**
* Reads the last output from the stdio process, parses and returns it * Reads the last output from the stdio process, parses and returns it
* *
* @return string * @return string
* @throws IDF_Scm_Exception * @throws IDF_Scm_Exception
*/ */
private function _read() private function _readStdout()
{ {
$this->oob = array('w' => array(), $this->oob = array('w' => array(),
'p' => array(), 'p' => array(),
@ -242,10 +260,10 @@ class IDF_Scm_Monotone_Stdio
$c = fgetc($this->pipes[1]); $c = fgetc($this->pipes[1]);
if ($c === false) if ($c === false)
{ {
$err = fgets($this->pipes[2]);
throw new IDF_Scm_Exception( throw new IDF_Scm_Exception(
"Could not read stdio: $err" "No data on stdin, stderr is:\n".
); $this->_readStderr()
);
} }
if ($c == ':') if ($c == ':')
@ -320,7 +338,7 @@ class IDF_Scm_Monotone_Stdio
public function exec(array $args, array $options = array()) public function exec(array $args, array $options = array())
{ {
$this->_write($args, $options); $this->_write($args, $options);
return $this->_read(); return $this->_readStdout();
} }
/** /**