/** * @When /^I run behat$/ */ public function iRunBehat() { $this->process->setWorkingDirectory($this->workingDir); $this->process->setCommandLine(sprintf('%s %s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), strtr('--format-settings=\'{"timer": false}\'', array('\'' => '"', '"' => '\\"')), '--format=progress')); $this->process->start(); $this->process->wait(); }
private function isSuccessful() { if (null === $this->isSuccessful) { $this->process->wait(); $this->isSuccessful = $this->process->isSuccessful(); } return $this->isSuccessful; }
/** * Runs behat command with provided parameters * * @When /^I run "behat(?: ((?:\"|[^"])*))?"$/ * * @param string $argumentsString */ public function iRunBehat($argumentsString = '') { $argumentsString = strtr($argumentsString, array('\'' => '"')); $this->process->setWorkingDirectory($this->workingDir); $this->process->setCommandLine(sprintf('%s %s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $argumentsString, strtr('--format-settings=\'{"timer": false}\' --no-colors', array('\'' => '"', '"' => '\\"')))); $this->process->start(); $this->process->wait(); }
/** * @param string $configurationAsString */ private function doRunBehat($configurationAsString) { $this->process->setWorkingDirectory($this->testApplicationDir); $this->process->setCommandLine(sprintf('%s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $configurationAsString)); $this->process->start(); $this->process->wait(); }
private function runCommand($cmd) { $process = new Process($cmd); $process->run(); $process->wait(); return $process; }
/** * Run a terminal command * @param [array] $command [description] * @param [path] $directory [description] * @param OutputInterface $output [description] * @return [void] [description] */ private function runProcess($command, $directory, $output, $alias) { $output->writeln(''); if (is_array($command['line'])) { $commandLine = implode(' && ', $command['line']); } else { $commandLine = $command['line']; } $process = new Process($commandLine, $directory); $process->setTimeout(7600); $process->start(); if ($output->isVerbose()) { $process->wait(function ($type, $buffer) { echo $buffer; }); } else { $progress = new ProgressBar($output); $progress->setFormat("<comment>%message%</comment> [%bar%]"); $progress->setMessage($command['title']); $progress->start(); $progress->setRedrawFrequency(10000); while ($process->isRunning()) { $progress->advance(); } $progress->finish(); $progress->clear(); } $output->writeln(''); $output->write('<comment>' . $command['title'] . ' </comment><info>√ done</info>'); }
/** * Executes the command $cmd * * @param string $cmd * @param \Symfony\Component\Console\Output\OutputInterface $output * @param bool $silent * @param bool $tty * @return string|void */ public function exec($cmd, $output = null, $silent = FALSE, $tty = FALSE) { $process = new Process($cmd); if ($tty) { $process->setTty(TRUE); } $process->setTimeout(null); if (!$silent && $output) { $output->writeln($this->messageService->lightGray('-------------------------------------------------')); $output->writeln($this->messageService->lightGray('Executing: ' . $cmd)); $messageService = $this->messageService; $process->setTimeout(3600); $process->start(); $process->wait(function ($type, $buffer) use($output, $messageService) { if (Process::ERR === $type) { $output->writeln($messageService->red('----> ERROR START')); $output->write($messageService->red('----> ' . $buffer)); $output->writeln($messageService->red('----> ERROR END')); } else { $output->write($messageService->green($buffer)); } }); } else { $process->run(); } return $process->getOutput(); }
protected function execute(InputInterface $input, OutputInterface $output) { $distribution = $input->getArgument('distribution'); $version = $input->getArgument('version'); $download = $this->downloadProject($distribution, $version); $process = new Process("tar -xzf {$download['location']} -C /tmp/"); $process->start(); if (substr($version, 0, 3) == '7.x') { $finder = new Finder(); $process->wait(); // Find all modules dropped in to the distribution. $finder->files()->name("*.info"); $filename = array(); foreach ($finder->in($download['locationUncompressed']) as $file) { $filename[] = array('path' => $file->getRealPath(), 'filename' => $file->getFileName()); } // Create the array for the containing modules. $return = array(); foreach ($filename as $file) { $contents = $this->parse_info_file(file_get_contents($file['path'])); $machine_name = substr($file['filename'], 0, strpos($file['filename'], '.')); $return[$machine_name] = array('name' => $contents['name'], 'machine_name' => substr($file['filename'], 0, strpos($file['filename'], '.')), 'core' => $contents['core'], 'version' => $contents['version'], 'status' => 'Enabled', 'package' => isset($contents['package']) ? $contents['package'] : null); } $output->write(json_encode($return)); } }
private function updateProject($docroot, $project, $version) { // Find the project, perform the update and applying patches (if applicable). $projectFilename = $this->substituteProjectName($project); $finder = new Finder(); $finder->files()->name("{$projectFilename}.info"); $filename = null; foreach ($finder->in($docroot) as $file) { $filename = $file->getRealPath(); } if (!is_null($filename)) { $locationVars = $this->downloadProject($project, $version); $process = new Process("tar -xzf {$locationVars['location']} -C /tmp/"); $process->start(); $samuraiYmlLocation = $this->findSamuraiYaml($docroot); $process->wait(); if (strlen($samuraiYmlLocation) > 0) { $this->applyPatches($locationVars, $docroot, $samuraiYmlLocation, $project); } $foldername = substr($filename, 0, -strlen("{$projectFilename}.info") - 1); $fs = new Filesystem(); $fs->remove($foldername); $fs->rename($locationVars['locationUncompressed'], $foldername); if (strlen($samuraiYmlLocation) > 0) { $this->cleanupPatching($docroot); } $this->cleanupPatching($docroot); } elseif ($project == 'drupal') { $locationVars = $this->downloadProject($project, $version); $process = new Process("tar -xzf {$locationVars['location']} -C /tmp/"); $process->start(); $samuraiYmlLocation = $this->findSamuraiYaml($docroot); $process->wait(); if (strlen($samuraiYmlLocation) > 0) { $this->applyPatches($locationVars, $docroot, $samuraiYmlLocation, $project); } $fs = new Filesystem(); $newCoreFiles = scandir($locationVars['locationUncompressed']); foreach ($newCoreFiles as $key => $file) { switch ($file) { case '..': case '.': case '.htaccess': case '.gitignore': case 'sites': unset($newCoreFiles[$key]); $file = null; break; } if (!is_null($file)) { $fs->remove($docroot . '/' . $file); $fs->rename($locationVars['locationUncompressed'] . '/' . $file, $docroot . '/' . $file); } } if (strlen($samuraiYmlLocation) > 0) { $this->cleanupPatching($docroot); } } }
/** * Execute a supervisorctl command * * @param $cmd string supervisorctl command * @return \Symfony\Component\Process\Process */ public function execute($cmd) { $p = new Process(sprintf('supervisorctl%1$s %2$s', $this->configurationParameter, $cmd)); $p->setWorkingDirectory($this->applicationDirectory); $p->run(); $p->wait(); return $p; }
/** * Runs phpspec command with provided parameters * * @When /^I run "phpspec(?: ((?:\"|[^"])*))?"$/ * * @param string $argumentsString */ public function iRunPhpspec($argumentsString = '') { $argumentsString = strtr($argumentsString, array('\'' => '"')); $this->process->setWorkingDirectory($this->workingDir); $this->process->setCommandLine(sprintf('%s %s %s --no-interaction', $this->phpBin, escapeshellarg($this->getPhpspecBinPath()), $argumentsString)); $this->process->start(); $this->process->wait(); }
/** * Process ctl command * * @param $cmd string supervisorctl command * @return Process */ public function execute($cmd) { $p = new Process("supervisorctl " . $cmd); $p->setWorkingDirectory($this->appDir); $p->run(); $p->wait(); return $p; }
/** * Runs behat command with provided parameters * * @When /^I run "filler(?: ((?:\"|[^"])*))?"$/ * * @param string $argumentsString */ public function iRunFiller($argumentsString = '') { $argumentsString = str_replace('{dir}', $this->workingDir, strtr($argumentsString, array('\'' => '"'))); $this->process->setWorkingDirectory($this->workingDir); $command = sprintf('%s %s %s', $this->phpBin, escapeshellarg($this->binDir . 'filler'), $argumentsString); $this->process->setCommandLine($command); $this->process->start(); // TODO store exit code and process output for verification $exitCode = $this->process->wait(); }
/** * Add optional promise to process options * * @param Process $process * @return Promise */ private function addPromise(Process $process) { /** @var Promise $promise */ $promise = new Promise(function () use($process, &$promise) { $process->wait(); $promise->resolve($process); }); $process->setOptions([ProcessQueue::PROMISE_KEY => $promise]); return $promise; }
/** * Execute the job. * @return void */ public function handle() { $shell = "/bin/bash " . $this->shellPath . '/resources/shell/deploy.sh' . ' ' . base_path() . ' ' . env('SL_DEPLOY_BRANCH', 'master'); $process = new Process($shell); $process->start(); $process->wait(function ($type, $buffer) { if (Process::ERR === $type) { echo 'ERR > ' . $buffer; } else { echo 'OUT > ' . $buffer; } }); }
/** * {@inheritdoc} */ public function wait(Process $process) { $start = microtime(true); $end = $start + $this->timeout / 1000; while (!$process->isTerminated() && microtime(true) < $end) { usleep(self::TICK * 1000); } if ($process->isRunning()) { $callback = $this->callback; $callback(); } $process->wait(); }
/** * Run child process. * * @param Daemonize $daemon * * @return mixed */ public function runChildProcess(Daemonize $daemon) { $this->output->setEnableAnsi(false); $this->output->setStdOut($this->log); $this->output->setStdErr($this->log); $this->process->start(); if (!$this->process->isRunning()) { throw new RuntimeException('Unable to start server process.'); } $this->processControl->setPid($this->process->getPid()); $this->process->wait(function ($type, $buffer) { $this->output->writeln($buffer); }); }
/** * Runs behat command with provided parameters * * @When /^I run "behat(?: ((?:\"|[^"])*))?"$/ * * @param string $argumentsString */ public function iRunBehat($argumentsString = '') { $argumentsString = strtr($argumentsString, array('\'' => '"')); $this->process->setWorkingDirectory($this->workingDir); $this->process->setCommandLine(sprintf('%s %s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $argumentsString, strtr('--format-settings=\'{"timer": false}\'', array('\'' => '"', '"' => '\\"')))); // Don't reset the LANG variable on HHVM, because it breaks HHVM itself if (!defined('HHVM_VERSION')) { $env = $this->process->getEnv(); $env['LANG'] = 'en'; // Ensures that the default language is en, whatever the OS locale is. $this->process->setEnv($env); } $this->process->start(); $this->process->wait(); }
public static function runAsRoot($cmd, \Closure $callback) { self::$cmd = $cmd = "sudo {$cmd}"; $process = new Process($cmd); $process->start(); $process->wait(function ($type, $buffer) { if (Process::ERR === $type) { //echo 'ERR > '.$buffer; } else { //echo 'OUT > '.$buffer; } }); // executes after the command finishes if (!$process->isSuccessful()) { throw new SudoProcessException($process->getErrorOutput()); } call_user_func($callback, false, $process->getOutput()); }
protected function execute(InputInterface $input, OutputInterface $output) { $silex = $this->getSilexApplication(); $basePath = $silex->getBasePath(); $host = $input->getOption('host'); $port = $input->getOption('port'); $php = trim(exec('/usr/bin/which php')); $command = "{$php} -S {$host}:{$port} -t {$basePath}/web {$basePath}/src/server.php"; $output->writeLn('<info>Starting built-in web server at ' . "{$host}:{$port}</info>"); $output->writeLn('<comment>Command : ' . $command . '</comment>'); $process = new Process($command); $process->setTimeout(null); $process->start(); $process->wait(function ($type, $buffer) use($output) { $output->writeln(sprintf("<comment>%s</comment>", trim($buffer))); }); $output->writeln('<info>Finished</info>'); }
/** * @param $output string|false * @return bool * @throws ProcessFailedException If the process was executed but failed */ public function execute(&$output) { if (!call_user_func($this->condition)) { return false; } $process = new Process($this->cmd); // NOTE: determine if keeping the return value might be useful $process->start(); $process->wait(); if (is_bool($output) && !$output) { $process->disableOutput(); } else { $output = $process->getOutput(); } if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } return true; }
/** * @param DBPatcher\PatchFile $patchFile * @param \Symfony\Component\Process\Process $process * @param resource $stdout * @param resource $stderr * @return DBPatcher\PatchFile */ function applyPhpPatch($patchFile, $process, $stdout = null, $stderr = null) { if ($patchFile->extension === 'php') { $process->setTimeout(null); $process->setIdleTimeout(null); $process->setCommandLine('/usr/bin/env php ' . $patchFile->filename); $process->start(function ($type, $buffer) use($stdout, $stderr) { $pipe = $type === Process::ERR && is_resource($stderr) ? $stderr : $stdout; if ($pipe) { fputs($pipe, $buffer); } }); if ($process->wait() === 0) { return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_INSTALLED)); } else { return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR), $process->getErrorOutput()); } } return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR)); }
/** * @param string $command * @param OutputInterface $output * @param callable|null $callback A valid PHP callback */ protected function basicProcess($command, OutputInterface $output, $callback = null) { $process = new Process($command); $process->setTimeout(600); $output->writeln($this->helper->formatSection('Executing', $process->getCommandLine(), 'comment')); $process->start(); $process->wait(function ($type, $buffer) use($output) { if (Process::ERR == $type) { $output->write($this->helper->formatSection('Error', $buffer, 'error')); } else { $output->write($this->helper->formatSection('Progress', $buffer, 'comment')); } }); if ($process->isTerminated()) { $output->writeln($this->helper->formatSection('Finishing', $process->getCommandLine(), 'comment')); if (null !== $callback) { $callback(); } } }
protected function shell($theme) { $process = new Process(trim(implode(' ', $this->argument('shell')))); $process->setWorkingDirectory(config('themes.path') . '/' . $theme); $process->setTimeout(null); $process->setIdleTimeout(null); $process->start(); $this->block("start theme <info>{$theme}'s</info> shell command!"); $process->wait(function ($type, $buffer) { if (Process::ERR === $type) { $this->error($buffer); } else { echo $buffer; } }); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } else { $this->block('run shell finish and everything is success!'); } }
public function executeCommand($command, $stdIn = null, $quiet = false) { $this->tty = $stdIn instanceof TTY; $command = $this->decorator->decorateCommand($command, $this); $this->process = $process = new Process($command, array_shift($this->workingDirectoriesStack)); $process->setTimeout(null); if (null !== $stdIn) { if ($this->tty) { $process->setTty(true); } else { $process->setStdin($stdIn); } } $output = $this->getOutput(); if ($output && $output->getVerbosity() >= $output::VERBOSITY_VERBOSE) { $output->writeln(sprintf('$ %s', $command)); $start = true; $prefix = ' ---> '; $process->start(function ($type, $buffer) use($output, &$start, $prefix, $quiet) { if ($start) { $buffer = $prefix . $buffer; $start = false; } if ($buffer[strlen($buffer) - 1] == "\n") { $start = true; $buffer = strtr(substr($buffer, 0, -1), ["\n" => "\n" . $prefix]) . "\n"; } else { $buffer = strtr($buffer, ["\n" => "\n" . $prefix]); } $quiet || $output->write($buffer); }); $process->wait(); } else { $process->run(); } if ($process->getExitCode() != 0) { throw new ProcessFailedException($process); } return $process->getOutput(); }
public function testIsRunning() { $process = new Process('php -r "sleep(1);"'); $this->assertFalse($process->isRunning()); $process->start(); $this->assertTrue($process->isRunning()); $process->wait(); $this->assertFalse($process->isRunning()); }
/** * {@inheritdoc} */ public function wait(Process $process) { $process->wait(); }
public function testIteratorInput() { $nextData = 'ping'; $input = function () use(&$nextData) { while (false !== $nextData) { (yield $nextData); (yield $nextData = ''); } }; $input = $input(); $process = new Process(self::$phpBin . ' -r ' . escapeshellarg('stream_copy_to_stream(STDIN, STDOUT);')); $process->setInput($input); $process->start(function ($type, $data) use($input, &$nextData) { if ('ping' === $data) { $h = fopen('php://memory', 'r+'); fwrite($h, 'pong'); rewind($h); $nextData = $h; $input->next(); } else { $nextData = false; } }); $process->wait(); $this->assertSame('pingpong', $process->getOutput()); }
private function runCommand($string, $timeout = 0) { $entityManager = $this->managerRegistry->getManagerForClass('DspSoftsCronManagerBundle:CronTaskLog'); try { $process = new Process($string); $process->setTimeout($timeout); $process->start(array($this, 'callbackProcess')); $this->cronTaskLog->setPid($process->getPid()); $entityManager->persist($this->cronTaskLog); $entityManager->flush(); $exitCode = $process->wait(); $this->cronTaskLog->setDateEnd(new \DateTime()); if ($exitCode > 0) { $this->cronTaskLog->setStatus(CronTaskLog::STATUS_FAILED); } elseif ($process->getErrorOutput() != '') { $this->cronTaskLog->setStatus(CronTaskLog::STATUS_WARNING); } else { $this->cronTaskLog->setStatus(CronTaskLog::STATUS_SUCCESS); } $this->cronTaskLog->setPid(null); $entityManager->persist($this->cronTaskLog); $entityManager->flush(); return $exitCode !== 0; } catch (\Exception $e) { $this->cronTaskLog->setStatus(CronTaskLog::STATUS_FAILED); $this->cronTaskLog->setPid(null); $this->cronTaskLog->setDateEnd(new \DateTime()); $entityManager->persist($this->cronTaskLog); $entityManager->flush(); return 1; } }
public function exec($cmd, $chdir = null) { $nl = true; // $output = $this->output; $process = new Process($cmd, $chdir); $process->setTimeout(null); $process->start(); $code = $process->wait(function ($type, $data) use($output, &$nl) { if ($nl === true) { $data = "\n" . $data; $nl = false; } if (substr($data, -1) === "\n") { $nl = true; $data = substr($data, 0, -1); } $data = str_replace("\n", "\n ", $data); $output($data); }); if ($nl) { $this->log(''); } if ($code !== 0) { throw new UnexpectedValueException('Error status code: ' . $process->getExitCodeText() . ' (code ' . $code . ')'); } }