コード例 #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;
     }
 }
コード例 #2
0
 /**
  * {@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
ファイル: PrepareReleaseJob.php プロジェクト: dzirg44/dogpro
 /**
  * @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;
     }
 }
コード例 #6
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
  *
  * @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
ファイル: RemoveCommand.php プロジェクト: vierbergenlars/clic
 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();
 }
コード例 #8
0
 /**
  * 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
ファイル: ProcessHelper.php プロジェクト: vierbergenlars/clic
 /**
  * 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
ファイル: PhpMp3Info.php プロジェクト: mhor/php-mp3info
 /**
  * @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
ファイル: ProcessBuilder.php プロジェクト: phpro/grumphp
 /**
  * @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
ファイル: Patcher.php プロジェクト: janvernieuwe/soap-client
 /**
  * @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
ファイル: Zip.php プロジェクト: alexandresalome/php-webdriver
 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
ファイル: RsyncSource.php プロジェクト: kachkaev/php-backup
 /**
  * {@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
ファイル: ImageQRCode.php プロジェクト: kofel/gutenberg
 /**
  * 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
ファイル: S3CmdDestination.php プロジェクト: kbond/php-backup
 /**
  * {@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
ファイル: AbstractProvider.php プロジェクト: octava/geggs
 /**
  * @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;
 }
コード例 #22
0
 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
ファイル: Composer.php プロジェクト: ArthurHlt/melody
 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
ファイル: Application.php プロジェクト: vierbergenlars/clic
 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
ファイル: Repository.php プロジェクト: gitiki/gitiki
 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
ファイル: Application.php プロジェクト: llaville/grumphp
 /**
  * {@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
ファイル: SatisRunner.php プロジェクト: yohang/satis-admin
 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()]);
     }
 }
コード例 #30
0
 /**
  * {@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());
     }
 }