Sets the current working directory.
public setWorkingDirectory ( string $cwd ) : self | ||
$cwd | string | The new working directory |
return | self | The current Process instance |
/** * 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('\'' => '"', '"' => '\\"')))); $this->process->run(); }
/** * @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(); }
public function execute() { $logger = $this->getRunConfig()->getLogger(); $this->process = new Process($this->command); $logger->info('Start command:' . $this->command); $this->process->setTimeout($this->timeout); $this->process->setWorkingDirectory($this->getRunConfig()->getRepositoryDirectory()); $this->process->run(); $output = trim($this->process->getOutput()); $logger->info($output); if (!$this->process->isSuccessful()) { $logger->emergency($this->process->getErrorOutput()); throw new \RuntimeException('Command not successful:' . $this->command); } }
/** * @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(); }
public static function shell($commands, array $opts = []) { //$cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array() if (is_array($commands)) { $procs = []; foreach ($commands as $command) { $procs[] = static::shell($command, $opts); } return $procs; } $process = new Process($commands); $options = array_replace(['type' => 'sync', 'cwd' => null, 'env' => null, 'timeout' => 60, 'callback' => null, 'output' => true], $opts); $options['cwd'] !== null && $process->setWorkingDirectory($options['cwd']); $options['env'] !== null && $process->setEnv($options['env']); is_int($options['timeout']) && $process->setTimeout($options['timeout']); if ($options['output'] === true) { $process->enableOutput(); } else { $process->disableOutput(); } $type = $options['type']; if ($type === 'sync') { $process->run($options['callback']); } elseif ($type === 'async') { $process->start(); } return $process; }
function render($context = null, $vars = array()) { $options = $this->options; $compress = @$options["compress"] ?: false; $outputFile = tempnam(sys_get_temp_dir(), 'metatemplate_template_less_output'); $finder = new ExecutableFinder(); $bin = @$this->options["less_bin"] ?: self::DEFAULT_LESSC; $cmd = $finder->find($bin); if ($cmd === null) { throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed."); } if ($compress) { $cmd .= ' -x'; } if (array_key_exists('include_path', $this->options)) { $cmd .= sprintf('--include-path %s', escapeshellarg(join(PATH_SEPARATOR, (array) $this->options['include_path']))); } $cmd .= " --no-color - {$outputFile}"; $process = new Process($cmd); $process->setStdin($this->getData()); if ($this->isFile()) { $process->setWorkingDirectory(dirname($this->source)); } $process->setEnv(array('PATH' => getenv("PATH"))); $process->run(); $content = @file_get_contents($outputFile); @unlink($outputFile); if (!$process->isSuccessful()) { throw new \RuntimeException("{$cmd} returned an error: " . $process->getErrorOutput()); } return $content; }
public function createProcess($command) { //echo ": $command\n"; $process = new Process($command); $process->setWorkingDirectory($this->repoDirectory); return $process; }
/** * Runs the given string as a command and returns the resulting output. * The CWD is set to the root project directory to simplify command paths. * * @param string $command * * @return string * * @throws ProcessFailedException in case the command execution is not successful */ private function runCommand($command, $workingDirectory = null) { $process = new Process($command); $process->setWorkingDirectory($workingDirectory ?: $this->rootDir); $process->mustRun(); return $process->getOutput(); }
public function run() { $command = $this->getCommand(); $dir = $this->workingDirectory ? " in " . $this->workingDirectory : ""; $this->printTaskInfo("Running <info>{$command}</info>{$dir}"); $this->process = new Process($command); $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) { print $buffer; }); $this->stopTimer(); return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]); } try { $this->process->start(); } catch (\Exception $e) { return Result::error($this, $e->getMessage()); } return Result::success($this); }
/** * @param InputInterface $input * @param OutputInterface $output * @return bool|null * TRUE is patch applies, FALSE if patch does not, and NULL if something * else occurs. */ protected function checkPatch(InputInterface $input, OutputInterface $output) { $issue = $this->getIssue($input->getArgument('url')); if ($issue) { $patch = $this->choosePatch($issue, $input, $output); if ($patch) { $patch = $this->getPatch($patch); $this->verbose($output, "Checking {$patch} applies"); $repo_dir = $this->getConfig()->getDrupalRepoDir(); $this->ensureLatestRepo($repo_dir); $process = new Process("git apply --check {$patch}"); $process->setWorkingDirectory($repo_dir); $process->run(); if ($process->isSuccessful()) { $this->output = $process->getOutput(); return TRUE; } else { $this->output = $process->getErrorOutput(); return FALSE; } } } // There is no patch, or there is a problem getting the issue. return NULL; }
function render($context = null, $vars = array()) { $finder = new ExecutableFinder(); $bin = @$this->options["tsc_bin"] ?: self::DEFAULT_TSC; $cmd = $finder->find($bin); if ($cmd === null) { throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed."); } $inputFile = sys_get_temp_dir() . '/pipe_typescript_input_' . uniqid() . '.ts'; file_put_contents($inputFile, $this->getData()); $outputFile = tempnam(sys_get_temp_dir(), 'pipe_typescript_output_') . '.js'; $cmd .= " --out " . escapeshellarg($outputFile) . ' ' . escapeshellarg($inputFile); $process = new Process($cmd); $process->setEnv(array('PATH' => @$_SERVER['PATH'] ?: join(PATH_SEPARATOR, array("/bin", "/sbin", "/usr/bin", "/usr/local/bin", "/usr/local/share/npm/bin")))); if ($this->isFile()) { $process->setWorkingDirectory(dirname($this->source)); } $process->run(); unlink($inputFile); if ($process->getErrorOutput()) { throw new \RuntimeException("tsc({$this->source}) returned an error:\n {$process->getErrorOutput()}"); } $data = file_get_contents($outputFile); unlink($outputFile); return $data; }
/** * {@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); }
public function run() { $command = $this->getCommand(); $dir = $this->workingDirectory ? " in " . $this->workingDirectory : ""; $this->printTaskInfo("running <info>{$command}</info>{$dir}"); $this->process = new Process($command); $this->process->setTimeout($this->timeout); $this->process->setIdleTimeout($this->idleTimeout); $this->process->setWorkingDirectory($this->workingDirectory); if (!$this->background and !$this->isPrinted) { $this->process->run(); return new Result($this, $this->process->getExitCode(), $this->process->getOutput()); } if (!$this->background and $this->isPrinted) { $this->process->run(function ($type, $buffer) { Process::ERR === $type ? print 'ER» ' . $buffer : (print '» ' . $buffer); }); return new Result($this, $this->process->getExitCode(), $this->process->getOutput()); } try { $this->process->start(); } catch (\Exception $e) { return Result::error($this, $e->getMessage()); } return Result::success($this); }
/** * Runs Behat with provided parameters. * * @When /^I run "behat(?: ((?:\"|[^"])*))?"$/ * * @param string $argumentsString */ public function iRunBehat($argumentsString = '') { $argumentsString = strtr($argumentsString, ['\'' => '"']); $this->behatProcess->setWorkingDirectory($this->workingDir); $this->behatProcess->setCommandLine(sprintf('%s %s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $argumentsString, strtr('--format-settings=\'{"timer": false}\' --no-colors', ['\'' => '"', '"' => '\\"']))); $this->behatProcess->start(); $this->behatProcess->wait(); }
/** * 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(); }
/** * Start supervisord if not already running */ public function run() { $result = $this->execute('status')->getOutput(); if (strpos($result, 'sock no such file') || strpos($result, 'refused connection')) { $p = new Process(sprintf('supervisord%1$s%2$s', $this->configurationParameter, $this->identifierParameter)); $p->setWorkingDirectory($this->applicationDirectory); $p->run(); } }
/** * Run supervisord */ public function run() { $result = $this->execute('status')->getOutput(); if (strpos($result, 'sock no such file') || strpos($result, 'refused connection')) { $p = new Process('supervisord'); $p->setWorkingDirectory($this->appDir); $p->run(); } }
/** * 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(); }
/** * 執行外部程式指令. * * @param string $command * @param string $baseDirectory * @return string */ protected function externalCommand($command, $baseDirectory = null) { $process = new Process($command); $process->setWorkingDirectory($baseDirectory ?? base_path()); $process->run(); if (!$process->isSuccessful()) { throw new RuntimeException($process->getErrorOutput()); } return $process->getOutput(); }
/** * @param string $cmd * @param string|null $workingDirectory * @param bool $isDryRun * @param bool $tty * @return $this */ public function add($cmd, $workingDirectory, $isDryRun = false, $tty = false) { $process = null; if (!$isDryRun) { $process = new Process($cmd); $process->setTty($tty); $process->setWorkingDirectory($workingDirectory); $this->parallelProcessRunner->add($process); } return $this; }
/** * @param $repository * @param $command * @return array */ protected function getCommandResult($repository, $command) { $process = new Process($command); $process->setWorkingDirectory($repository->getPath()); $process->run(); $output = trim($process->getOutput()); if ($output === '') { return []; } return explode("\n", $output); }
public function testDrushBootstrap() { $app = $this->createApplication(); $commandline = realpath('./vendor/bin/drush'); $process = new Process($commandline . ' core-status version --pipe'); $process->setWorkingDirectory(realpath('./vendor/drupal/drupal')); $process->run(); $output = json_decode($process->getOutput(), true); $this->assertArrayHasKey('drupal-version', $output); $this->assertArrayHasKey('drush-version', $output); }
private function execute($option, \SplFileInfo $file) { $command = 'java -jar tika-app-1.7.jar ' . $option . ' ' . $file->getRealPath(); $cwd = __DIR__ . '/vendor/'; $process = new Process($command); $process->setWorkingDirectory($cwd); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } return $process->getOutput(); }
/** * @param $repository * @return string * @throws \Swis\GoT\Exception\CannotFindRemoteException */ protected function getRemoteUrl(Repository $repository) { try { $process = new Process('git config --get remote.origin.url'); $process->setWorkingDirectory($repository->getPath()); $process->run(); $output = trim($process->getOutput()); } catch (\Exception $e) { throw new Exception\CannotFindRemoteException(); } return $output; }
/** * @param string $option * @param string $fileName * @return string * @throws RuntimeException */ private static function run($option, $fileName) { $file = new SplFileInfo($fileName); $tikaPath = __DIR__ . "/../vendor/"; $shellCommand = 'java -jar tika-app-1.5.jar ' . $option . ' "' . $file->getRealPath() . '"'; $process = new Process($shellCommand); $process->setWorkingDirectory($tikaPath); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } return $process->getOutput(); }
/** * Tests a basic installation. */ public function testBasicInstallation() { if (PHP_VERSION_ID < 50600) { $this->markTestSkipped('Majora requires PHP 5.6 or higher.'); } $this->fs->remove(sprintf('%s/TestProject', $this->rootDir)); $process = new Process(sprintf('php %s/bin/majora new testProject', realpath(dirname(dirname(dirname(dirname(__DIR__))))))); $process->setWorkingDirectory($this->rootDir); $process->mustRun(); $output = $process->getOutput(); $this->assertContains('Downloading Majora Standard Edition...', $output); $this->assertContains('[OK] Majora Standard Edition master was successfully installed', $output); }
/** * Set working directory and process kill timeout * * @param string $workingDirectory * @param int $timeout * * @throws \Exception */ public function setOptions($workingDirectory = '.', $timeout = 0) { if ($this->process !== null) { if ($workingDirectory !== '.') { $this->process->setWorkingDirectory($workingDirectory); } if ($timeout > 0) { $this->process->setTimeout($timeout); } } else { throw new \Exception('First create a process!'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $kernel = $this->getContainer()->get('kernel'); /** @var $kernel Kernel */ $res = $kernel->locateResource('@AvanzuAdminThemeBundle/Resources/bower'); $helper = $this->getHelperSet()->get('formatter'); /** @var $helper FormatterHelper */ $bower = $this->getContainer()->getParameter('avanzu_admin_theme.bower_bin'); $action = $input->getOption('update') ? 'update' : 'install'; $asRoot = $input->getOption('root') ? '--allow-root' : ''; $process = new Process($bower . ' ' . $action . ' ' . $asRoot); $process->setTimeout(600); $output->writeln($helper->formatSection('Executing', $process->getCommandLine(), 'comment')); $process->setWorkingDirectory($res); $process->run(function ($type, $buffer) use($output, $helper) { if (Process::ERR == $type) { $output->write($helper->formatSection('Error', $buffer, 'error')); } else { $output->write($helper->formatSection('Progress', $buffer, 'info')); } }); // no more pulling/cloning directly from master in favor of a bower installation with specific version constraint /* $process = new Process('git clone https://github.com/almasaeed2010/AdminLTE.git'); $process->setWorkingDirectory(dirname($res).'/public/vendor'); // run checkout if no dir present // run update only if update requested $process = null; $adminlte_dir = dirname($res).'/public/vendor/AdminLTE'; if($input->getOption('update')) { $process = new Process('git pull'); $process->setWorkingDirectory($adminlte_dir); } $output->writeln($helper->formatSection('Executing',$process->getCommandLine(), 'comment')); if(!is_dir($adminlte_dir)) { $process = new Process('git clone https://github.com/almasaeed2010/AdminLTE.git'); $process->setWorkingDirectory(dirname($adminlte_dir)); } if ($process) { $output->writeln($helper->formatSection('Executing',$process->getCommandLine(), 'comment')); $process->run(function($type, $buffer) use ($output, $helper){ if(Process::ERR == $type) { $output->write($helper->formatSection('Error', $buffer, 'error' )); } else { $output->write($helper->formatSection('Progress', $buffer, 'info' )); } }); } */ }
public function testWordpressBootstrap() { $app = $this->createApplication(); $commandline = realpath('./vendor/wp-cli/wp-cli/bin/wp core config'); $process = new \Symfony\Component\Process\Process($commandline); $process->setWorkingDirectory(realpath('./vendor/wordpress/wordpress')); $process->run(); $output = $process->getOutput(); $script = $app['php.wordpress36.bootstrap'](); $process = new \Symfony\Component\Process\PhpProcess('<?php ' . $script, realpath('./vendor/wordpress/wordpress')); $process->setWorkingDirectory(realpath('./vendor/wordpress/wordpress')); $process->run(); $output = $process->getOutput(); }
protected function executeCommand($command) { $process = new SymfonyProcess($command); $process->setWorkingDirectory($this->workingDirectory); $process->setTimeout(null); if ($this->isPrinted) { $process->run(function ($type, $buffer) { SymfonyProcess::ERR === $type ? print 'ER» ' . $buffer : (print $buffer); }); } else { $process->run(); } return new Result($this, $process->getExitCode(), $process->getOutput()); }