当前位置: 首页>>代码示例>>PHP>>正文


PHP Process::getExitCode方法代码示例

本文整理汇总了PHP中Symfony\Component\Process\Process::getExitCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::getExitCode方法的具体用法?PHP Process::getExitCode怎么用?PHP Process::getExitCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Process\Process的用法示例。


在下文中一共展示了Process::getExitCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check

 /**
  * {@inheritdoc}
  */
 public function check()
 {
     if (!$this->isSuccessful()) {
         // on some systems stderr is used, but on others, it's not
         throw new LintingException($this->process->getErrorOutput() ?: $this->process->getOutput(), $this->process->getExitCode());
     }
 }
开发者ID:fabpot,项目名称:php-cs-fixer,代码行数:10,代码来源:ProcessLintingResult.php

示例2: runProcess

 /**
  * @param Process     $process
  * @param bool        $mustRun
  * @param bool        $quiet
  *
  * @return int|string
  * @throws \Exception
  */
 protected function runProcess(Process $process, $mustRun = false, $quiet = true)
 {
     if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
         $this->output->writeln("Running command: <info>" . $process->getCommandLine() . "</info>");
     }
     try {
         $process->mustRun($quiet ? null : function ($type, $buffer) {
             $this->output->write(preg_replace('/^/m', '  ', $buffer));
         });
     } catch (ProcessFailedException $e) {
         if (!$mustRun) {
             return $process->getExitCode();
         }
         // The default for ProcessFailedException is to print the entire
         // STDOUT and STDERR. But if $quiet is disabled, then the user will
         // have already seen the command's output.  So we need to re-throw
         // the exception with a much shorter message.
         $message = "The command failed with the exit code: " . $process->getExitCode();
         $message .= "\n\nFull command: " . $process->getCommandLine();
         if ($quiet) {
             $message .= "\n\nError output:\n" . $process->getErrorOutput();
         }
         throw new \Exception($message);
     }
     $output = $process->getOutput();
     return $output ? rtrim($output) : true;
 }
开发者ID:ecolinet,项目名称:platformsh-cli,代码行数:35,代码来源:ShellHelper.php

示例3: validateRun

 /**
  * Validate that a run process was successful.
  *
  * @throws \RuntimeException
  * @return void
  */
 protected function validateRun()
 {
     $status = $this->process->getExitCode();
     $error = $this->process->getErrorOutput();
     if ($status !== 0 and $error !== '') {
         throw new \RuntimeException(sprintf("The exit status code %s says something went wrong:\n stderr: %s\n stdout: %s\ncommand: %s.", $status, $error, $this->process->getOutput(), $this->command));
     }
 }
开发者ID:vuthaihoc,项目名称:pdf-parser,代码行数:14,代码来源:Process.php

示例4: iRunTheCommand

 /**
  * @When I run the tenanted command :command
  * @When I run the tenanted command :command with options :options
  * @param $command
  * @param $options
  */
 public function iRunTheCommand($command, $options = null)
 {
     $this->actualCommand = $command;
     $tenantedCommand = 'bin/tenant ' . $options . ' ' . PHP_BINARY . ' test/Vivait/TenantBundle/app/console --no-ansi ' . $command;
     $this->process = new Process($tenantedCommand);
     $this->process->run();
     PHPUnit_Framework_Assert::assertSame(0, $this->process->getExitCode(), 'Non zero return code received from command');
 }
开发者ID:kieljohn,项目名称:TenantBundle,代码行数:14,代码来源:CommandContext.php

示例5: assertExitCodeError

 /**
  * @param Process  $composer
  * @param int|null $error
  */
 protected function assertExitCodeError(Process $composer, $error = null)
 {
     if ($error !== null) {
         $this->assertEquals($error, $composer->getExitCode(), 'Expected ' . $error . ' error code');
     } else {
         $this->assertNotEquals(0, $composer->getExitCode(), 'Expected not success error code');
     }
 }
开发者ID:javihgil,项目名称:composer-ci-tools,代码行数:12,代码来源:ScriptFunctionalTestCase.php

示例6: getStatus

 function getStatus()
 {
     if ($this->process->isRunning()) {
         return TestInterface::STATUS_RUNNING;
     } elseif ($this->process->getExitCode() > 0) {
         return TestInterface::STATUS_FAIL;
     } else {
         return TestInterface::STATUS_OK;
     }
 }
开发者ID:mburtscher,项目名称:network-checker,代码行数:10,代码来源:ProcessTest.php

示例7: handleProcessResult

 protected function handleProcessResult(Process $process)
 {
     $this->processObjectList[] = $process;
     if ($process->getExitCode() !== 0) {
         $message = $messageEnd = 'process for <code>' . $process->getCommandLine() . '</code> exited with ' . $process->getExitCode() . ': ' . $process->getExitCodeText();
         $message .= PHP_EOL . 'Error Message:' . PHP_EOL . $process->getErrorOutput();
         $message .= PHP_EOL . 'Output:' . PHP_EOL . $process->getOutput();
         $message .= PHP_EOL . $messageEnd;
         throw new \Exception($message, $process->getExitCode());
     }
 }
开发者ID:AydinHassan,项目名称:composer-test-framework,代码行数:11,代码来源:Wrapper.php

示例8: exec

 public function exec($cmd)
 {
     $preparedCmd = $this->prepareCommand($cmd);
     if ($this->logger) {
         $this->logger->debug('preparedCmd: ' . $preparedCmd);
     }
     $process = new Process($preparedCmd, null, null, null, $this->timeout);
     $process->run();
     $this->lastOutput = $process->getOutput();
     $this->lastError = $process->getErrorOutput();
     $process->getExitCode();
     return $process->getExitCode();
 }
开发者ID:skedone,项目名称:DeployBundle,代码行数:13,代码来源:CLISshProxy.php

示例9: execute

 /**
  * @param  string            $commandline
  * @param  bool              $allowFailure
  * @param  string            $cwd
  * @throws \RuntimeException
  * @return int|null
  */
 public function execute($commandline, $cwd = null, $allowFailure = false)
 {
     $process = new Process($commandline, $cwd);
     $process->setTimeout(self::DEFAULT_TIMEOUT);
     $output = $this->output;
     // tmp var needed for php < 5.4
     $process->run(function ($type, $buffer) use($output) {
         $output->write($buffer);
     });
     if (!$allowFailure && !$process->isSuccessful()) {
         throw new \RuntimeException("Command failed. Error Output:\n\n" . $process->getErrorOutput(), $process->getExitCode());
     }
     return $process->getExitCode();
 }
开发者ID:0x4,项目名称:sw-cli-tools,代码行数:21,代码来源:ProcessExecutor.php

示例10: runCommand

 /**
  * Run the given command.
  *
  * @param  string  $command
  * @param  callable $onError
  * @return string
  */
 function runCommand($command, callable $onError = null)
 {
     $onError = $onError ?: function () {
     };
     $process = new Process($command);
     $processOutput = '';
     $process->setTimeout(null)->run(function ($type, $line) use(&$processOutput) {
         $processOutput .= $line;
     });
     if ($process->getExitCode() > 0) {
         $onError($process->getExitCode(), $processOutput);
     }
     return $processOutput;
 }
开发者ID:laravel,项目名称:valet,代码行数:21,代码来源:CommandLine.php

示例11: prepareView

 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     parent::prepareView($view);
     if (!isset($this->process)) {
         return;
     }
     if ($this->getRequest()->isMutation()) {
         if ($this->process->getExitCode() === 0) {
             $view->getCommandList()->shutdown($view->getModuleUrl() . '?wait=0', $this->parameters['Action'], array($view->translate('shutdown_' . $this->parameters['Action']), $view->translate('test')));
         } else {
             $view->getCommandList('/Notification')->showMessage("error " . $this->process->getOutput(), \Nethgui\Module\Notification\AbstractNotification::NOTIFY_ERROR);
         }
     }
 }
开发者ID:sitz-air,项目名称:nethserver-base,代码行数:14,代码来源:Shutdown.php

示例12: execute

 /**
  * runs a process on the commandline
  *
  * @param  string $command the command to execute
  * @param  mixed  $output  the output will be written into this var if passed by ref
  *                         if a callable is passed it will be used as output handler
  * @param  string $cwd     the working directory
  * @return int    statuscode
  */
 public function execute($command, &$output = null, $cwd = null)
 {
     if ($this->io && $this->io->isDebug()) {
         $safeCommand = preg_replace_callback('{://(?P<user>[^:/\\s]+):(?P<password>[^@\\s/]+)@}i', function ($m) {
             if (preg_match('{^[a-f0-9]{12,}$}', $m['user'])) {
                 return '://***:***@';
             }
             return '://' . $m['user'] . ':***@';
         }, $command);
         $this->io->writeError('Executing command (' . ($cwd ?: 'CWD') . '): ' . $safeCommand);
     }
     // make sure that null translate to the proper directory in case the dir is a symlink
     // and we call a git command, because msysgit does not handle symlinks properly
     if (null === $cwd && Platform::isWindows() && false !== strpos($command, 'git') && getcwd()) {
         $cwd = realpath(getcwd());
     }
     $this->captureOutput = count(func_get_args()) > 1;
     $this->errorOutput = null;
     $process = new Process($command, $cwd, null, null, static::getTimeout());
     $callback = is_callable($output) ? $output : array($this, 'outputHandler');
     $process->run($callback);
     if ($this->captureOutput && !is_callable($output)) {
         $output = $process->getOutput();
     }
     $this->errorOutput = $process->getErrorOutput();
     return $process->getExitCode();
 }
开发者ID:detain,项目名称:composer,代码行数:36,代码来源:ProcessExecutor.php

示例13: run

 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->printAction();
     $this->process = new Process($this->getCommand());
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (isset($this->env)) {
         $this->process->setEnv($this->env);
     }
     if (!$this->background and !$this->isPrinted) {
         $this->startTimer();
         $this->process->run();
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     if (!$this->background and $this->isPrinted) {
         $this->startTimer();
         $this->process->run(function ($type, $buffer) {
             $progressWasVisible = $this->hideTaskProgress();
             print $buffer;
             $this->showTaskProgress($progressWasVisible);
         });
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::fromException($this, $e);
     }
     return Result::success($this);
 }
开发者ID:jjok,项目名称:Robo,代码行数:36,代码来源:Exec.php

示例14: testSleeperCommand

 /**
  * @group console
  */
 public function testSleeperCommand()
 {
     // init
     $sleeperCommand = new SleeperCommand();
     $sleeperCommandLockFilePath = sprintf('%s/lock_command_%s', $this->getClient()->getKernel()->getCacheDir(), str_replace(':', '_', $sleeperCommand->getName()));
     $commandline = sprintf('env bin/console --env=%s %s', $this->getClient()->getKernel()->getEnvironment(), $sleeperCommand->getName());
     // the first run of this command with the locking mechanism: the lock is created
     $firstProcess = new Process($commandline);
     $firstProcess->start();
     sleep(SleeperCommand::SLEEPING_TIME / 2);
     // the second run of this command is invalid
     $secondProcess = new Process($commandline);
     $secondProcess->run();
     $this->assertSame(2, $secondProcess->getExitCode(), 'Invalid exit code');
     $secondProcessOutput = $secondProcess->getOutput();
     $this->assertSame(2, substr_count($secondProcessOutput, PHP_EOL), 'There is more than two lines');
     $this->assertContains('locking is activated', $secondProcessOutput, 'Incorrect line 1');
     $this->assertContains('will not be started', $secondProcessOutput, 'Incorrect line 2');
     // check the first process is still running
     $this->assertTrue($firstProcess->isRunning(), sprintf('The command %s does not work', $firstProcess->getCommandLine()));
     // after the sleeping, the lock is released
     sleep(1 + SleeperCommand::SLEEPING_TIME / 2);
     $this->assertSame(0, $firstProcess->getExitCode());
     $firstProcessOutput = $firstProcess->getOutput();
     $this->assertSame(3, substr_count($firstProcessOutput, PHP_EOL), 'There is more than three lines');
     $this->assertContains('starting', $firstProcessOutput);
     $this->assertContains('processing', $firstProcessOutput);
     $this->assertContains('ending', $firstProcessOutput);
     // the third run of this command, after the sleeping, is valid
     $thirdProcess = new Process($commandline);
     $thirdProcess->run();
     $this->assertSame(0, $thirdProcess->getExitCode());
 }
开发者ID:kmelia,项目名称:fresh-symfony,代码行数:36,代码来源:LockingTest.php

示例15: databaseExists

 /**
  * Check if the given database already exists
  *
  * @param  \ClickRain\Breeze\Model\Database $database
  * @return boolean
  */
 public function databaseExists(Database $database)
 {
     $script = sprintf('mysql --user="root" --password="secret" -e "use %s"', $database->local_name);
     $process = new Process($script);
     $process->run();
     return !$process->getExitCode();
 }
开发者ID:clickrain,项目名称:breeze,代码行数:13,代码来源:DatabaseHelper.php


注:本文中的Symfony\Component\Process\Process::getExitCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。