コード例 #1
0
ファイル: Process.php プロジェクト: tifabien/symfony
 /**
  * Waits for the process to terminate.
  *
  * The callback receives the type of output (out or err) and some bytes
  * from the output in real-time while writing the standard input to the process.
  * It allows to have feedback from the independent process during execution.
  *
  * @param callable|null $callback A valid PHP callback
  *
  * @return int The exitcode of the process
  *
  * @throws RuntimeException When process timed out
  * @throws RuntimeException When process stopped after receiving signal
  * @throws LogicException   When process is not yet started
  */
 public function wait(callable $callback = null)
 {
     $this->requireProcessIsStarted(__FUNCTION__);
     $this->updateStatus(false);
     if (null !== $callback) {
         if (!$this->processPipes->haveReadSupport()) {
             $this->stop(0);
             throw new \LogicException('Pass the callback to the Process:start method or enableOutput to use a callback with Process::wait');
         }
         $this->callback = $this->buildCallback($callback);
     }
     do {
         $this->checkTimeout();
         $running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
         $close = '\\' !== DIRECTORY_SEPARATOR || !$running;
         $this->readPipes(true, $close);
     } while ($running);
     while ($this->isRunning()) {
         usleep(1000);
     }
     if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
         throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
     }
     return $this->exitcode;
 }