本文整理汇总了PHP中Symfony\Component\Process\Process::getOutput方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::getOutput方法的具体用法?PHP Process::getOutput怎么用?PHP Process::getOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::getOutput方法的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());
}
}
示例2: execute
public function execute($template, array $parameters)
{
$bootstrap = $this->getBootstrapPath();
if ($bootstrap && !file_exists($bootstrap)) {
throw new \InvalidArgumentException(sprintf('Bootstrap file "%s" does not exist', $bootstrap));
}
if (!file_exists($template)) {
throw new \RuntimeException(sprintf('Could not find script template "%s"', $template));
}
$parameters['bootstrap'] = $bootstrap;
$tokens = array();
foreach ($parameters as $key => $value) {
$tokens['{{ ' . $key . ' }}'] = $value;
}
$templateBody = file_get_contents($template);
$script = str_replace(array_keys($tokens), array_values($tokens), $templateBody);
$scriptPath = tempnam(sys_get_temp_dir(), 'PhpBench');
file_put_contents($scriptPath, $script);
$process = new Process(PHP_BINARY . ' ' . $scriptPath);
$process->run();
unlink($scriptPath);
if (false === $process->isSuccessful()) {
throw new \RuntimeException(sprintf('Could not execute script: %s %s', $process->getErrorOutput(), $process->getOutput()));
}
$output = $process->getOutput();
$result = json_decode($output, true);
if (null === $result) {
throw new \RuntimeException(sprintf('Could not decode return value from script from template "%s" (should be a JSON encoded string): %s', $template, $output));
}
return $result;
}
示例3: testIntegration
/**
* @dataProvider getTestFiles
*/
public function testIntegration(\SplFileInfo $testFile)
{
$testData = $this->parseTestFile($testFile);
$cmd = 'php ' . __DIR__ . '/../../../bin/composer --no-ansi ' . $testData['RUN'];
$proc = new Process($cmd);
$exitcode = $proc->run();
if (isset($testData['EXPECT'])) {
$this->assertEquals($testData['EXPECT'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
}
if (isset($testData['EXPECT-REGEX'])) {
$this->assertRegExp($testData['EXPECT-REGEX'], $this->cleanOutput($proc->getOutput()), 'Error Output: ' . $proc->getErrorOutput());
}
if (isset($testData['EXPECT-ERROR'])) {
$this->assertEquals($testData['EXPECT-ERROR'], $this->cleanOutput($proc->getErrorOutput()));
}
if (isset($testData['EXPECT-ERROR-REGEX'])) {
$this->assertRegExp($testData['EXPECT-ERROR-REGEX'], $this->cleanOutput($proc->getErrorOutput()));
}
if (isset($testData['EXPECT-EXIT-CODE'])) {
$this->assertSame($testData['EXPECT-EXIT-CODE'], $exitcode);
}
// Clean up.
$fs = new Filesystem();
if (isset($testData['test_dir']) && is_dir($testData['test_dir'])) {
$fs->removeDirectory($testData['test_dir']);
}
}
示例4: test
public function test(array $configurationFiles)
{
$path = rtrim(sys_get_temp_dir(), '/') . '/' . uniqid('nagadmin-test');
mkdir($path);
$checkResultPath = $path . '/checkresults';
mkdir($checkResultPath, 0777);
$logFilePath = '/dev/null';
$configurationFiles[] = $this->createMainConfigFile($path, $configurationFiles, $checkResultPath, $logFilePath);
$this->writer->write($path, $configurationFiles);
try {
$process = new Process('nagios --verify-config ' . escapeshellarg($path . '/nagios.cfg') . ' 2>&1');
$process->setTimeout(10);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getOutput());
}
$isValid = true;
$checkOutput = $process->getOutput();
} catch (\RuntimeException $e) {
$isValid = false;
$checkOutput = $e->getMessage();
}
$this->writer->cleanup($path);
rmdir($path);
return array($isValid, $checkOutput);
}
示例5: compile
/**
* @return string
*/
public function compile()
{
$this->stopwatch->start('webpack.total');
$this->stopwatch->start('webpack.prepare');
// Recompile twig templates where its needed.
$this->addSplitPoints();
$this->addResolveConfig();
// Write the webpack configuration file.
file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.config.js', $this->generator->getConfiguration());
$this->profiler->set('compiler.performance.prepare', $this->stopwatch->stop('webpack.prepare')->getDuration());
$this->stopwatch->start('webpack.compiler');
$this->process->run();
$output = $this->process->getOutput() . $this->process->getErrorOutput();
$this->profiler->set('compiler.executed', true);
$this->profiler->set('compiler.successful', strpos($output, 'Error:') === false);
$this->profiler->set('compiler.last_output', $output);
if ($this->profiler->get('compiler.successful')) {
$this->tracker->rebuild();
}
// Finally, write some logging for later use.
file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.compiler.log', $output);
$this->profiler->set('compiler.performance.compiler', $this->stopwatch->stop('webpack.compiler')->getDuration());
$this->profiler->set('compiler.performance.total', $this->stopwatch->stop('webpack.total')->getDuration());
return $output;
}
示例6: exec
/**
* Execute an SVN command
*
* @param string $cmd Command name (update, info, etc)
* @param array $arguments An array of argument (path, url, etc)
* @param array $options An array of options
* @param string $path Working directory
* @param integer $timeout Timeout
*
* @return string
* @throws \Exception
*/
public static function exec($cmd, $arguments = array(), $options = array(), $path = null, $output = false, $timeout = null)
{
if (!is_array($arguments)) {
$arguments = array($arguments);
}
$arguments = array_map("escapeshellarg", $arguments);
$new_options = array();
foreach ($options as $key => $value) {
$new_options[] = preg_replace("/[^-\\w]/", "", $key);
if ($value !== true) {
$new_options[] = escapeshellarg($value);
}
}
$cmdline = "svn {$cmd} " . implode(" ", $arguments) . " " . implode(" ", $new_options);
$process = new Process($cmdline, $path, null, null, $timeout);
$process->run();
if (!$process->isSuccessful()) {
throw new RuntimeException($process->getErrorOutput());
}
if ($output) {
echo $process->getOutput();
return null;
}
return $process->getOutput();
}
示例7: runShellCommand
/**
* Executes a shell command.
*
* @param string $command
*
* @return $this
*/
public function runShellCommand($command)
{
$this->process = new Process($command);
$this->exitCode = $this->process->run();
$this->stdOutput = $this->process->getOutput();
$this->stdError = $this->process->getErrorOutput();
return $this;
}
示例8: iSeeInline
/**
* @Then I see :output
*/
public function iSeeInline($output)
{
$actual = trim($this->process->getOutput());
$expected = trim($output);
if ($expected !== $actual) {
throw new \Exception(sprintf('"%s" != "%s"', $actual, $expected));
}
}
示例9: run
/**
* @param Process $process
*/
public function run(Process $process)
{
$this->logger->debug(sprintf('Webhook process started: "%s".', $command = $process->getCommandLine()));
$process->run();
if ($process->isSuccessful()) {
$this->logger->debug(sprintf('Webhook process finished: "%s".', $command), ['output' => $process->getOutput()]);
} else {
$this->logger->error(sprintf('Webhook process errored: "%s".', $command), ['output' => $process->getOutput(), 'error' => $process->getErrorOutput()]);
}
}
示例10: runCommand
/**
* Returns the result for the command string.
*
* @param string $command The command string.
* @param string $dir The working directory path.
* @param boolean $throw Throw an exception on error?
*
* @return string The output from the command or null if there is an
* error and an exception was not thrown.
*
* @throws RuntimeException If there is a problem running the command.
*/
private function runCommand($command, $dir, $throw = true)
{
$process = new Process($command, $dir);
if (0 === $process->run()) {
return trim($process->getOutput()) ?: null;
}
if ($throw) {
throw new RuntimeException(sprintf("Git repository error:\n\nOutput:\n%s\n\nError:%s", $process->getOutput() ?: '(none)', $process->getErrorOutput() ?: '(none)'));
}
return null;
}
示例11: perform
/**
* Perform a test with a given parameter
*
* @param TestableSubjectInterface $subject
*
* @return float|bool
*/
public function perform(TestableSubjectInterface $subject)
{
$process = new Process(base_path('/resources/speedtest-cli --server ' . $subject->getTesterParameter()));
$process->setTimeout($this->timeout)->run();
if ($process->isSuccessful() && strpos($process->getOutput(), $this->pattern) !== false) {
// Extract speed result from the command output
$speed = substr($process->getOutput(), strpos($process->getOutput(), $this->pattern) + mb_strlen($this->pattern));
return floatval(substr($speed, 0, strpos($speed, ' ')));
} else {
return false;
}
}
示例12: testBuildPhar
public function testBuildPhar()
{
$fs = new Filesystem();
$fs->remove(dirname(self::$pharPath));
$this->ensureDirectoryExists(dirname(self::$pharPath));
chdir(dirname(self::$pharPath));
$proc = new Process('php ' . escapeshellarg(__DIR__ . '/../../bin/compile'), dirname(self::$pharPath));
$exitcode = $proc->run();
if ($exitcode !== 0 || trim($proc->getOutput())) {
$this->fail($proc->getOutput());
}
$this->assertTrue(file_exists(self::$pharPath));
}
示例13: _reconfigure
/**
* {@inheritDoc}
*
* Starts the connection
*/
public function _reconfigure($config = array())
{
parent::_reconfigure($config);
if (!isset($this->config['username'])) {
throw new \Exception("Sauce Connect Extension requires a username.");
}
if (!isset($this->config['accesskey'])) {
throw new \Exception("Sauce Connect Extension requires a accesskey.");
}
$connect = __DIR__ . '/../../../bin/sauce_connect';
if (!file_exists($connect)) {
$connect = __DIR__ . '/../../../../bin/sauce_connect';
}
if (!file_exists($connect)) {
throw new \Exception("Couldnt find the bin directory... Make sure its in ./bin or ./vendor/bin/");
}
$processBuilder = new ProcessBuilder([$connect]);
$processBuilder->addEnvironmentVariables(['SAUCE_USERNAME' => $this->config['username'], 'SAUCE_ACCESS_KEY' => $this->config['accesskey']]);
$timeout = isset($this->config['timeout']) ? $this->config['timeout'] : 60;
$this->process = $processBuilder->getProcess();
$this->process->setTimeout(0);
$this->process->start(function ($type, $buffer) {
$buffer = explode("\n", $buffer);
foreach ($buffer as $line) {
if (strpos($line, 'Press any key to see more output') === false) {
file_put_contents(codecept_output_dir() . 'sauce_connect.log', $line . "\n", FILE_APPEND);
}
}
});
$timer = 0;
$connected = false;
$this->writeln(["", "----------------------------------------------------------------------------", "Attempting to connect to SauceLabs. Waiting {$timeout} seconds."]);
while ($this->process->isRunning() && $timer < $timeout) {
$output = $this->process->getOutput();
if (strpos($output, 'Connected! You may start your tests.') !== false) {
$connected = true;
break;
}
sleep(1);
$timer++;
if ($timer % 5 === 0) {
$this->write('.');
}
}
if (false === $connected) {
$this->process->stop();
throw new \Exception(sprintf("Could not start tunnel. Check %ssauce_connect.log for more information.", codecept_output_dir()));
}
$this->writeln(["", "Connected to SauceLabs", "----------------------------------------------------------------------------", ""]);
}
示例14: 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);
}
}
}
示例15: run
/**
* @param string $bin
* @param array $args
* @return string
*/
public function run($bin, $args)
{
if (!is_file($bin)) {
throw new \InvalidArgumentException(sprintf('Binary %s not found', $bin));
}
$process = new Process(sprintf('"%s" %s', $bin, escapeshellcmd($this->arrayToArgsString($args))));
$process->run();
if (!$process->isSuccessful()) {
$this->logger->critical($process->getErrorOutput());
throw new \RuntimeException($process->getErrorOutput());
}
$this->logger->debug(sprintf('SIPS Request output: %s', $process->getOutput()));
return $process->getOutput();
}