|
@@ -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'));
|
|
|
|