getIncrementalErrorOutput() public method

In comparison with the getErrorOutput method which always return the whole error output, this one returns the new error output since the last call.
public getIncrementalErrorOutput ( ) : string
return string The process error output since the last call
 /**
  * Looks into and processes the child's output
  *
  * @param string $childName
  * @return void
  */
 public function processOutput($childName)
 {
     $output = $this->outputBuffer . $this->process->getIncrementalOutput();
     $errorOutput = $this->errorOutputBuffer . $this->process->getIncrementalErrorOutput();
     $outputLines = explode("\n", $output);
     $errorOutputLines = explode("\n", $errorOutput);
     if (count($outputLines) > 0) {
         $lastItem = array_pop($outputLines);
         $this->outputBuffer = $lastItem;
         $this->bufferLength += implode("\n", $outputLines);
         foreach ($outputLines as $line) {
             if (strstr($line, "[[CHILD::BUSY]]")) {
                 $this->parent->verboseOutput('<info>' . $childName . ' BUSY</info>');
                 $this->status = ChildProcessContainer::STATUS_BUSY;
             } elseif (strstr($line, "[[CHILD::READY]]")) {
                 $this->parent->verboseOutput('<info>' . $childName . ' READY</info>');
                 if ($this->status != ChildProcessContainer::STATUS_BUSY_BUT_SLEEPY) {
                     $this->status = ChildProcessContainer::STATUS_READY;
                 } else {
                     $this->status = ChildProcessContainer::STATUS_SLEEPY;
                 }
             } elseif (strlen($line) > 0) {
                 $this->parent->verboseOutput('<info>OUTPUT ' . $childName . ':</info>' . $line);
             }
         }
     }
     if (count($errorOutputLines) > 0) {
         $lastItemError = array_pop($errorOutputLines);
         $this->errorOutputBuffer = $lastItemError;
         $knownErrorOutput = implode("\n", $errorOutputLines);
         $this->bufferLength += strlen($knownErrorOutput);
     }
 }
 /**
  * Executes post install SH script
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param OutputInterface                                 $output
  *
  * @internal param \Symfony\Component\Console\Input\InputInterface $intput
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $command = $input->getOption("post");
     $output->writeln("");
     $output->writeln("========================");
     $output->writeln('Executing post ' . $command . ' script.');
     $output->writeln("========================");
     // TODO: openssl req -new -x509 -sha256 -days 365 -nodes -out /tmp/server.crt -keyout /tmp/server.key
     $process = new Process("/bin/bash ./src/FIT/NetopeerBundle/bin/netconfwebgui-postinstall.sh");
     $process->run();
     while ($process->isRunning()) {
         $process->getIncrementalOutput();
         $process->getIncrementalErrorOutput();
     }
     if (!$process->isSuccessful()) {
         $output->writeln("Error in post " . $command . " script occured.");
         $output->writeln($process->getErrorOutput());
     } else {
         $output->writeln($process->getOutput());
     }
     $output->writeln("========================");
     $output->writeln("End of post " . $command . " script");
     $output->writeln("========================");
 }
 public function testGetIncrementalErrorOutput()
 {
     $p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { usleep(50000); file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
     $p->start();
     while ($p->isRunning()) {
         $this->assertLessThanOrEqual(1, preg_match_all('/ERROR/', $p->getIncrementalErrorOutput(), $matches));
         usleep(20000);
     }
 }
示例#4
0
 /**
  * @param $address
  * @param $environment
  */
 protected function startServer()
 {
     $publicDir = $this->getApplication()->getWorkingPath() . DS . 'public';
     $shellCommand = $this->getBaseCommand();
     $process = new Process($shellCommand, $publicDir);
     if ($this->getInput()->getOption('background')) {
         $process->disableOutput();
         $process->start();
         $processId = $this->getProcessId();
         $this->getApplication()->getConfig()->setOption('server', ['pid' => $processId, 'address' => $address = 'http://' . $this->getAddress()]);
         $this->getOutput()->writeln($this->info('Server has been started at ' . $address));
     } else {
         while ($process instanceof Process) {
             if (!$process->isStarted()) {
                 $process->start();
                 continue;
             }
             echo $process->getIncrementalOutput();
             echo $process->getIncrementalErrorOutput();
             if (!$process->isRunning() || $process->isTerminated()) {
                 $process = false;
                 $this->getOutput()->writeln("");
                 $this->getOutput()->writeln($this->info('Server has been stopped.'));
             }
             sleep(1);
         }
     }
 }
示例#5
0
 /**
  * @param Process $process
  * @return callable
  */
 public function updateRelease(Process $process)
 {
     $out = $process->getIncrementalOutput() . $process->getIncrementalErrorOutput();
     $this->release->update(['raw_log' => $process->getOutput() . PHP_EOL . $process->getErrorOutput()]);
     if (!empty($out)) {
         $this->release->logger()->info($out);
     }
 }
示例#6
0
 /**
  * Decorate and return Process output
  * @param Process $process
  * @return string
  */
 protected function getProcessOutput(Process $process)
 {
     $output = '';
     // Add standard process output
     if ($processOutput = $process->getIncrementalOutput()) {
         $processOutputLines = explode("\n", $processOutput);
         // color output lines containing "[WARN]"
         foreach ($processOutputLines as &$processOutputLine) {
             if (strpos($processOutputLine, '[WARN]') !== false) {
                 $processOutputLine = '<fg=black;bg=yellow>' . $processOutputLine . '</fg=black;bg=yellow>';
             } elseif (strpos($processOutputLine, '[DEBUG]') !== false) {
                 $processOutputLine = '<comment>' . $processOutputLine . '</comment>';
             }
         }
         $output .= implode("\n", $processOutputLines);
     }
     // Add error output
     if ($errorOutput = $process->getIncrementalErrorOutput()) {
         $output .= '<error>' . rtrim($errorOutput, PHP_EOL) . '</error>' . "\n";
     }
     return $output;
 }