clearErrorOutput() public method

Clears the process output.
public clearErrorOutput ( ) : Process
return Process
示例#1
0
 /**
  * {@inheritdoc}
  */
 public function processScript(CliScript $script)
 {
     $log = $this->getLog();
     $log->info('Executing "{script}" script', ['script' => $script->getScript()]);
     // New process, with timeout
     $process = new Process($script->getScript());
     $process->setTimeout($script->getTimeout());
     // Run process
     $process->run(function ($type, $buffer) use($log) {
         // Trim
         $buffer = trim($buffer);
         // Don't log empty output
         if (empty($buffer)) {
             return;
         }
         if (Process::OUT === $type) {
             $log->debug($buffer);
             return;
         }
         $log->error($buffer);
     });
     // Abort if process failed
     if (!$process->isSuccessful()) {
         // Remove the error output
         $process->clearErrorOutput();
         // Throw failure
         throw new ScriptFailedException(sprintf('Script "%s" has filed', $script->getScript()));
     }
 }
 public function testFlushErrorOutput()
 {
     $p = new Process(sprintf('php -r %s', escapeshellarg('$n = 0; while ($n < 3) { file_put_contents(\'php://stderr\', \'ERROR\'); $n++; }')));
     $p->run();
     $p->clearErrorOutput();
     $this->assertEmpty($p->getErrorOutput());
 }