示例#1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = $this->getContainer()->getParameter('chebur_sphinx_config');
     $configFile = $config['config']['destination'];
     //Проверяем на существование файла конфига
     if (!file_exists($configFile)) {
         $output->writeln('<error>Config file not found. Run "chebur:sphinx:generate" first.</error>');
         return;
     }
     $pb = ProcessBuilder::create()->inheritEnvironmentVariables()->setPrefix($config['commands']['bin'] . DIRECTORY_SEPARATOR . 'searchd')->add('--config')->add($configFile)->add('--stop');
     $process = $pb->getProcess();
     $process->start();
     $output->writeln('<info>executing</info> ' . $process->getCommandLine());
     while ($process->isRunning()) {
         if (!$process->getOutput()) {
             continue;
         }
         $output->writeln($process->getOutput());
         $process->clearOutput();
     }
     $output->writeln($process->getOutput());
     if (!$process->isSuccessful()) {
         $output->writeln('<error>' . $process->getExitCodeText() . '</error>');
         return;
     }
 }
 /**
  * {@inheritdoc}
  *
  * @see PlatformCommand::getCurrentEnvironment()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $now = new \DateTime();
     // Hopefully this isn't too opinionated?
     $workingDir = dirname($this->behatLocation);
     if (!is_dir($workingDir . '/vendor')) {
         $output->writeln("<error>Assumed behat directory doesn't have depednencies installed: {$workingDir}.");
         exit(1);
     }
     // Try to find the Behat binary
     $composerData = json_decode(file_get_contents($workingDir . '/composer.json'), true);
     if (isset($composerData['config']['bin-dir'])) {
         $binDir = $composerData['config']['bin-dir'];
     } else {
         $binDir = 'vendor/bin/';
     }
     $outPath = Platform::rootDir() . '/behat-run-' . $now->getTimestamp() . '.log';
     $builder = ProcessBuilder::create([$binDir . 'behat', '--format=pretty', '--out=' . $outPath]);
     $builder->setWorkingDirectory($workingDir);
     $builder->setTimeout(null);
     $process = $builder->getProcess();
     // @todo: export environment variables (postponed.)
     // @note there's also v2 v3 issues we'd have to sort out for exporting.
     //          just run the dang thing.
     $output->writeln("<info>Running Behat, saving output to {$outPath}");
     $this->startSeleniumContainer();
     $process->run();
     $this->stopSeleniumContainer();
     if (!$process->isSuccessful()) {
         $output->writeln($process->getErrorOutput());
     }
 }
 /**
  * @inheritdoc
  */
 public function create()
 {
     if (null === $this->binary) {
         throw new InvalidArgumentException('No binary set');
     }
     return ProcessBuilder::create(array($this->binary))->setTimeout(null);
 }
示例#4
0
 /**
  * @throws ReleaseException
  */
 private function extractArchive()
 {
     $process = ProcessBuilder::create(["tar", "-xvf", $this->release->path("build.tar.gz")])->setWorkingDirectory($this->release->path())->getProcess();
     if ($process->run() !== 0) {
         throw new ReleaseException($this->release, "Release failed, export repo: " . $process->getErrorOutput());
     }
 }
示例#5
0
文件: Step.php 项目: silverstripe/cow
 /**
  * Run an arbitrary command
  *
  * To display errors/output make sure to run with -vvv
  *
  * @param OutputInterface $output
  * @param string|array|Process $command An instance of Process or an array of arguments to escape and run
  * or a command to run
  * @param string|null $error An error message that must be displayed if something went wrong
  * @param bool $exceptionOnError If an error occurs, this message is an exception rather than a notice
  * @return bool|string Output, or false if error
  * @throws Exception
  */
 public function runCommand(OutputInterface $output, $command, $error = null, $exceptionOnError = true)
 {
     $helper = $this->getProcessHelper();
     // Prepare unbound command
     if (is_array($command)) {
         $process = ProcessBuilder::create($command)->getProcess();
     } elseif ($command instanceof Process) {
         $process = $command;
     } else {
         $process = new Process($command);
     }
     // Run it
     $process->setTimeout(null);
     $result = $helper->run($output, $process, $error);
     // And cleanup
     if ($result->isSuccessful()) {
         return $result->getOutput();
     } else {
         if ($exceptionOnError) {
             $error = $error ?: "Command did not run successfully";
             throw new Exception($error);
         }
         return false;
     }
 }
 /**
  * Runs an external process.
  *
  * @param OutputInterface      $output    An OutputInterface instance
  * @param string|array|Process $cmd       An instance of Process or an array of arguments to escape and run or a command to run
  * @param string|null          $error     An error message that must be displayed if something went wrong
  * @param callable|null        $callback  A PHP callback to run whenever there is some
  *                                        output available on STDOUT or STDERR
  * @param int                  $verbosity The threshold for verbosity
  *
  * @return Process The process that ran
  */
 public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
 {
     $formatter = $this->getHelperSet()->get('debug_formatter');
     if (is_array($cmd)) {
         $process = ProcessBuilder::create($cmd)->getProcess();
     } elseif ($cmd instanceof Process) {
         $process = $cmd;
     } else {
         $process = new Process($cmd);
     }
     if ($verbosity <= $output->getVerbosity()) {
         $output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
     }
     if ($output->isDebug()) {
         $callback = $this->wrapCallback($output, $process, $callback);
     }
     $process->run($callback);
     if ($verbosity <= $output->getVerbosity()) {
         $message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
         $output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
     }
     if (!$process->isSuccessful() && null !== $error) {
         $output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
     }
     return $process;
 }
示例#7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $processHelper = $this->getHelper('process');
     /* @var $processHelper ProcessHelper */
     $appConfig = $configHelper->getConfiguration()->getApplication($input->getArgument('application'));
     $applicationVhosts = $appConfig->getVhosts();
     if ($input->getOption('remove-vhosts') && count($applicationVhosts) > 0) {
         $this->getApplication()->find('vhost:remove')->run(new ArrayInput(['vhosts' => array_map(function (VhostConfiguration $vhostConfiguration) {
             return $vhostConfiguration->getName();
         }, $applicationVhosts)]), $output);
         $applicationVhosts = $appConfig->getVhosts();
     }
     if (count($applicationVhosts) > 0) {
         throw new \RuntimeException(sprintf('This application has active vhosts: %s', implode(', ', array_map(function (VhostConfiguration $vhostConfig) {
             return $vhostConfig->getName();
         }, $applicationVhosts))));
     }
     $output->write(sprintf('Remove application <info>%s</info>...', $appConfig->getName()));
     if ($input->getOption('purge')) {
         $output->writeln(sprintf('Purging <comment>%s</comment>', $appConfig->getPath()));
         $processHelper->mustRun($output, ProcessBuilder::create(['rm', '-rf', $appConfig->getPath()])->getProcess());
     }
     $configHelper->getConfiguration()->removeApplication($appConfig->getName());
     $output->writeln('<info>OK</info>');
     $configHelper->getConfiguration()->write();
 }
 /**
  * AbstractDiagnoser constructor.
  *
  * @param ProcessHelper $processHelper
  */
 public function __construct(ProcessHelper $processHelper)
 {
     $this->processHelper = $processHelper;
     $this->process = ProcessBuilder::create($this->getProcessDefinition())->getProcess();
     $this->output = new NullOutput();
     $this->transformer = $this->getTransformer();
 }
示例#9
0
 /**
  * Runs an external process.
  *
  * @param OutputInterface      $output    An OutputInterface instance
  * @param string|array|Process $cmd       An instance of Process or an array of arguments to escape and run or a command to run
  * @param string|null          $error     An error message that must be displayed if something went wrong
  * @param callable|null        $callback  A PHP callback to run whenever there is some
  *                                        output available on STDOUT or STDERR
  * @param int                  $verbosity The threshold for verbosity
  * @param int                  $lineVerbosity Threshold for verbosity to show all output of the process
  *
  * @return Process The process that ran
  */
 public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE, $lineVerbosity = OutputInterface::VERBOSITY_DEBUG)
 {
     if ($output instanceof ConsoleOutputInterface) {
         $output = $output->getErrorOutput();
     }
     $formatter = $this->getHelperSet()->get('debug_formatter');
     /* @var $formatter DebugFormatterHelper */
     if (is_array($cmd)) {
         $process = ProcessBuilder::create($cmd)->getProcess();
     } elseif ($cmd instanceof Process) {
         $process = $cmd;
     } else {
         $process = new Process($cmd);
     }
     if ($verbosity <= $output->getVerbosity()) {
         $output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
         $output->write($formatter->progress(spl_object_hash($process), $this->escapeString($process->getWorkingDirectory()), false, 'DIR'));
         $output->write($formatter->progress(spl_object_hash($process), PHP_EOL));
     }
     if ($lineVerbosity <= $output->getVerbosity()) {
         $callback = $this->wrapCallback($output, $process, $callback);
     }
     $process->run($callback);
     if ($verbosity <= $output->getVerbosity()) {
         $message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
         $output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
     }
     if (!$process->isSuccessful() && null !== $error) {
         $output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
     }
     return $process;
 }
示例#10
0
 /**
  * @param ProcessBuilder $processBuilder
  */
 public function __construct($processBuilder = null)
 {
     if ($processBuilder === null) {
         $this->processBuilder = ProcessBuilder::create()->setPrefix(array($this->command, $this->arguments));
     } else {
         $this->processBuilder = $processBuilder;
     }
 }
示例#11
0
文件: Git.php 项目: lilocon/deploy
 private function createProcessBuilder($command)
 {
     $git_bin = $this->config['staging']['bin']['git'];
     $processBuilder = ProcessBuilder::create([$git_bin, $command]);
     $processBuilder->setTimeout(60);
     $processBuilder->setWorkingDirectory($this->config['staging']['repo']['work_dir']);
     return $processBuilder;
 }
示例#12
0
 /**
  * @param ProcessArgumentsCollection $arguments
  *
  * @return Process
  * @throws \GrumPHP\Exception\PlatformException
  */
 public function buildProcess(ProcessArgumentsCollection $arguments)
 {
     $builder = SymfonyProcessBuilder::create($arguments->getValues());
     $builder->setTimeout($this->config->getProcessTimeout());
     $process = $builder->getProcess();
     $this->logProcessInVerboseMode($process);
     $this->guardWindowsCmdMaxInputStringLimitation($process);
     return $process;
 }
示例#13
0
 /**
  * @param $patch
  *
  * @return string
  */
 protected function applyPatch($patch)
 {
     $process = ProcessBuilder::create(['patch', '-N', '--input=' . $patch])->setWorkingDirectory($this->tmpFolder)->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new PatchException('Patch failed: ' . $process->getOutput());
     }
     return $process->getOutput();
 }
示例#14
0
 public function addFile($file)
 {
     $args = array('zip', '-j', $this->path, $file);
     $process = ProcessBuilder::create($args)->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new LibraryException('Error while running zip command: ' . $process->getErrorOutput());
     }
 }
示例#15
0
 /**
  * {@inheritdoc}
  */
 public function fetch($scratchDir, LoggerInterface $logger)
 {
     $logger->info(sprintf('Syncing files from: %s', $this->source));
     $process = ProcessBuilder::create($this->options)->setTimeout($this->timeout)->setPrefix('rsync')->add($this->source)->add($scratchDir)->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
 }
 public function onBeforeScenarioTested()
 {
     $processBuilder = ProcessBuilder::create()->setPrefix($this->binary)->add('site-install')->add($this->drupal->getProfile())->add('--sites-subdir=' . $this->drupal->getSiteDir())->add('--account-name=admin')->add('--account-pass=password')->add('--yes')->setWorkingDirectory($this->drupal->getPath())->setTimeout(null)->setEnv('PHP_OPTIONS', '-d sendmail_path=' . `which true`);
     $this->eventDispatcher->dispatch(InstallingSite::NAME, $event = new InstallingSite($this->drupal, $processBuilder));
     if (!$event->isPropagationStopped()) {
         $this->processRunner->run($processBuilder->getProcess());
         $this->eventDispatcher->dispatch(SiteInstalled::NAME, new SiteInstalled($this->drupal));
     }
 }
示例#17
0
文件: Spawn.php 项目: bouiboui/spawn
 /**
  * Convenience function to build and add a process to spawn
  * @param array $arguments
  */
 private function addProcess(array $arguments = [])
 {
     $process = ProcessBuilder::create(explode(' ', $arguments[0]));
     // $arguments[0] = command
     foreach (array_slice($arguments, 1) as $singleArgument) {
         $process->add($singleArgument);
     }
     $this->processes[] = $process;
 }
示例#18
0
 /**
  * Encodes string into QR code image
  * @param $data
  * @return Image
  */
 public static function encode($data)
 {
     $process = ProcessBuilder::create(['qrencode', '-l', 'L', '-s', '8', '-m', '0', '-o', '-', $data])->getProcess();
     $process->run();
     if ($process->isSuccessful()) {
         $image = Image::fromBinary($process->getOutput());
         return $image;
     }
 }
示例#19
0
 /**
  * {@inheritdoc}
  */
 public function all()
 {
     $process = ProcessBuilder::create($this->options)->setPrefix(array('s3cmd', 'ls'))->add(trim($this->bucket, '/') . '/')->setTimeout($this->timeout)->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     return new BackupCollection($this->parseS3CmdListOutput($process->getOutput()));
 }
示例#20
0
 /**
  * @param string $command
  * @param array  $arguments
  * @return string
  */
 public function buildCommand($command, array $arguments = [])
 {
     array_unshift($arguments, $command);
     $bin = $this->config->getGitBin();
     $builder = ProcessBuilder::create($arguments);
     $builder->setPrefix($bin);
     $cmd = $builder->getProcess()->getCommandLine();
     $cmd = 'cd ' . $this->getRepositoryPath() . ' && ' . $cmd;
     return $cmd;
 }
示例#21
0
 /**
  * {@inheritdoc}
  */
 public function process($scratchDir, Namer $namer, LoggerInterface $logger)
 {
     $filename = sprintf('%s/%s.%s', sys_get_temp_dir(), $namer->generate(), $this->extension);
     $logger->info(sprintf('Archiving files to: %s', $filename));
     $process = ProcessBuilder::create(array($this->command, $this->options, $filename, './'))->setWorkingDirectory($scratchDir)->setTimeout($this->timeout)->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     return $filename;
 }
 public static function setUpBeforeClass()
 {
     if (version_compare(PHP_VERSION, '5.4.0', '<')) {
         self::markTestSkipped('PHP Webserver is available from PHP 5.4');
     }
     $phpFinder = new PhpExecutableFinder();
     self::$webserver = ProcessBuilder::create(array('exec', $phpFinder->find(), '-S', sprintf('localhost:%d', WEBSERVER_PORT), '-t', __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures'))->getProcess();
     self::$webserver->start();
     usleep(100000);
     self::$websererPortLength = strlen(WEBSERVER_PORT);
 }
示例#23
0
 public function getVendorDir()
 {
     $args = array_merge($this->composerCommand, array('config', '--global', 'vendor-dir'));
     $process = ProcessBuilder::create($args)->getProcess()->mustRun();
     $output = trim($process->getOutput());
     // Composer could add a message telling the version is outdated like:
     // "This development build of composer is over 30 days old"
     // We should take the last line.
     $outputByLines = explode(PHP_EOL, $output);
     return end($outputByLines);
 }
示例#24
0
文件: Git.php 项目: 3wil/GIFTploy
 /**
  * Returns configured and prepared process.
  *
  * @param string $command   Command to execute
  * @param array $args       Additional arguments
  * @param array $options    Options to override
  *
  * @return \Symfony\Component\Process\Process   Prepared process to run
  */
 public static function getProcess($command, array $args = [], array $options = [])
 {
     $options = array_merge($options, self::$options);
     $builder = \Symfony\Component\Process\ProcessBuilder::create(array_merge([$options["command"]], $command, $args));
     $builder->inheritEnvironmentVariables(false);
     $process = $builder->getProcess();
     $process->setEnv($options["environment_variables"]);
     $process->setTimeout($options["process_timeout"]);
     $process->setIdleTimeout($options["process_timeout"]);
     return $process;
 }
示例#25
0
 public function getProcessBuilder(array $arguments = [])
 {
     $env = [];
     foreach ($_SERVER as $key => $value) {
         $ev = getenv($key);
         if ($ev) {
             $env[$key] = $ev;
         }
     }
     return ProcessBuilder::create($arguments)->setWorkingDirectory($this->getPath())->addEnvironmentVariables($env)->setTimeout(null);
 }
示例#26
0
 public function run($command, $args = [])
 {
     $output = parent::run($command, $args);
     if ('diff-tree' === $command && null !== $this->perlCommand) {
         $p = ProcessBuilder::create([$this->perlCommand, __DIR__ . '/../Resources/bin/git-diff-highlight'])->setInput($output)->getProcess();
         $p->run();
         if ($p->isSuccessful()) {
             $output = $p->getOutput();
         }
     }
     return $output;
 }
示例#27
0
 /**
  * {@inheritdoc}
  */
 protected function getDefaultCommands()
 {
     $container = $this->getContainer();
     $commands = parent::getDefaultCommands();
     $commands[] = new Command\ConfigureCommand($container->get('config'), $container->get('filesystem'), $container->get('git.repository'), $container->get('task_runner'));
     $commands[] = new Command\RunCommand($container->get('config'), $container->get('locator.registered_files'));
     $commands[] = new Command\Git\CommitMsgCommand($container->get('config'), $container->get('locator.changed_files'));
     $commands[] = new Command\Git\DeInitCommand($container->get('config'), $container->get('filesystem'));
     $commands[] = new Command\Git\InitCommand($container->get('config'), $container->get('filesystem'), ProcessBuilder::create());
     $commands[] = new Command\Git\PreCommitCommand($container->get('config'), $container->get('locator.changed_files'));
     return $commands;
 }
示例#28
0
 public function run()
 {
     $configFile = tempnam(sys_get_temp_dir(), 'satis-admin');
     file_put_contents($configFile, $this->manager->getJson());
     $process = ProcessBuilder::create(['php', $this->binDir . '/satis', 'build', $configFile, $this->outputDir])->getProcess();
     $this->logger->addInfo('Building config...', ['command-line' => $process->getCommandLine()]);
     if (0 === $process->run()) {
         $this->logger->addInfo('Config built.');
     } else {
         $this->logger->addError('Config not build', ['stdout' => $process->getOutput(), 'stderr' => $process->getErrorOutput()]);
     }
 }
示例#29
0
 public function run()
 {
     $configFile = tempnam($this->cacheDir . '/satis', 'satis-admin');
     file_put_contents($configFile, $this->manager->getJson());
     $process = ProcessBuilder::create(['php', $this->binDir . '/satis', 'build', $configFile, $this->outputDir])->setTimeout(null)->addEnvironmentVariables(['HOME' => $this->cacheDir])->getProcess();
     $this->logger->addInfo('Building config...', ['command-line' => $process->getCommandLine()]);
     if (0 === $process->run()) {
         unlink($configFile);
         $this->logger->addInfo('Config built.');
     } else {
         $this->logger->addError('Config not build', ['stdout' => $process->getOutput(), 'stderr' => $process->getErrorOutput()]);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $builder = ProcessBuilder::create(['composer', 'create-project', 'drupalcommerce/project-base', $input->getArgument('project'), '--stability', 'dev']);
     $builder->setTimeout(null);
     $builder->enableOutput();
     $process = $builder->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         $output->writeln($process->getErrorOutput());
     } else {
         $output->writeln($process->getOutput());
     }
 }