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