From 54655104cabf2a8c1dae2946eb2bb94ec085b7c1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 1 Apr 2011 18:07:53 +0200 Subject: [PATCH] [Process] changed run() behavior to always populate getOutput() and getErrorOutput() --- src/Symfony/Component/Process/Process.php | 32 ++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 89ed49583b..73b32e4282 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -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) - { - if ('out' == $type) { - $that->addOutput($line); - } else { - $that->addErrorOutput($line); - } - }; - } + $this->stdout = ''; + $this->stderr = ''; + $that = $this; + $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'));