[Process] changed run() behavior to always populate getOutput() and getErrorOutput()

This commit is contained in:
Fabien Potencier 2011-04-01 18:07:53 +02:00
parent 1a486492b8
commit 54655104ca

View File

@ -70,8 +70,8 @@ class Process
* some bytes from the output in real-time. It allows to have feedback
* from the independent process during execution.
*
* If you don't provide a callback, the STDOUT and STDERR are available only after
* the process is finished via the getOutput() and getErrorOutput() methods.
* The STDOUT and STDERR are also available after the process is finished
* via the getOutput() and getErrorOutput() methods.
*
* @param Closure|string|array $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
@ -84,19 +84,21 @@ class Process
*/
public function run($callback = null)
{
if (null === $callback) {
$this->stdout = '';
$this->stderr = '';
$that = $this;
$callback = function ($type, $line) use ($that)
$callback = function ($type, $line) use ($that, $callback)
{
if ('out' == $type) {
$that->addOutput($line);
} else {
$that->addErrorOutput($line);
}
};
if (null !== $callback) {
call_user_func($callback, $type, $line);
}
};
$descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));