/** * Build a Process to run tivodecode decoding a file with a MAK * * @param string $mak TiVo's Media Access Key * @param string $input Where the encoded TiVo file is * @param string $output Where the decoded MPEG file goes * * @return Process */ protected function buildProcess($mak, $input, $output) { $this->builder->setPrefix('/usr/local/bin/tivodecode'); $this->builder->setArguments([$input, '--mak=' . $mak, '--no-verify', '--out=' . $output]); $this->builder->setTimeout(null); return $this->builder->getProcess(); }
/** * Build a Process to run avahi-browse looking for TiVo on TCP * * @return Process */ protected function buildProcess() { $this->builder->setPrefix('avahi-browse'); $this->builder->setArguments(['--ignore-local', '--resolve', '--terminate', '_tivo-videos._tcp']); $this->builder->setTimeout(60); return $this->builder->getProcess(); }
/** * Asynchronously start mediainfo operation. * Make call to MediaInfoCommandRunner::wait() afterwards to receive output. */ public function start() { $this->processBuilder->add($this->filePath); $this->processAsync = $this->processBuilder->getProcess(); // just takes advantage of symfony's underlying Process framework // process runs in background $this->processAsync->start(); }
/** * Function to install Laravel * * @return string directory where app was installed */ public function install() { $this->command->comment("Foreman", "Installing fresh Laravel app"); $this->builder->setPrefix('composer'); $this->builder->setArguments(['create-project', 'laravel/laravel', $this->appDir, '--prefer-dist']); $this->builder->getProcess()->run(); $this->command->comment("Foreman", "Done, Laravel installed at: {$this->appDir}"); return $this->appDir; }
/** * @return string */ public function run() { $this->processBuilder->add($this->filePath); $process = $this->processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } return $process->getOutput(); }
/** * @return string * @throws \RuntimeException */ protected function executeCommand() { $this->processBuilder->setArguments(array()); $this->processBuilder->add($this->filePath); $process = $this->processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } return $process->getOutput(); }
/** * Get a property from youtube-dl. * * @param string $url URL to parse * @param string $format Format * @param string $prop Property * * @return string */ private function getProp($url, $format = null, $prop = 'dump-json') { $this->procBuilder->setArguments(['--' . $prop, $url]); if (isset($format)) { $this->procBuilder->add('-f ' . $format); } $process = $this->procBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { throw new \Exception($process->getErrorOutput()); } else { return $process->getOutput(); } }
/** * Execute this task * * @param \TYPO3\Surf\Domain\Model\Node $node * @param \TYPO3\Surf\Domain\Model\Application $application * @param \TYPO3\Surf\Domain\Model\Deployment $deployment * @param array $options * @throws \TYPO3\Surf\Exception\InvalidConfigurationException * @return void */ public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) { $this->assertRequiredOptionsExist($options); $dumpCommand = new ProcessBuilder(); $dumpCommand->setPrefix('mysqldump'); $dumpCommand->setArguments(array('-h', $options['sourceHost'], '-u', $options['sourceUser'], '-p' . $options['sourcePassword'], $options['sourceDatabase'])); $mysqlCommand = new ProcessBuilder(); $mysqlCommand->setPrefix('mysql'); $mysqlCommand->setArguments(array('-h', $options['targetHost'], '-u', $options['targetUser'], '-p' . $options['targetPassword'], $options['targetDatabase'])); $arguments = array(); $username = isset($options['username']) ? $options['username'] . '@' : ''; $hostname = $node->getHostname(); $arguments[] = $username . $hostname; if ($node->hasOption('port')) { $arguments[] = '-P'; $arguments[] = $node->getOption('port'); } $arguments[] = $mysqlCommand->getProcess()->getCommandLine(); $sshCommand = new ProcessBuilder(); $sshCommand->setPrefix('ssh'); $sshCommand->setArguments($arguments); $command = $dumpCommand->getProcess()->getCommandLine() . ' | ' . $sshCommand->getProcess()->getCommandLine(); $localhost = new Node('localhost'); $localhost->setHostname('localhost'); $this->shell->executeOrSimulate($command, $localhost, $deployment); }
/** * @param BinaryInterface $binary * @param array $options * * @throws ProcessFailedException * * @return BinaryInterface */ public function processWithConfiguration(BinaryInterface $binary, array $options) { $type = strtolower($binary->getMimeType()); if (!in_array($type, array('image/jpeg', 'image/jpg'))) { return $binary; } $pb = new ProcessBuilder(array($this->mozjpegBin)); // Places emphasis on DC $pb->add('-quant-table'); $pb->add(2); $transformQuality = array_key_exists('quality', $options) ? $options['quality'] : $this->quality; if ($transformQuality !== null) { $pb->add('-quality'); $pb->add($transformQuality); } $pb->add('-optimise'); // Favor stdin/stdout so we don't waste time creating a new file. $pb->setInput($binary->getContent()); $proc = $pb->getProcess(); $proc->run(); if (false !== strpos($proc->getOutput(), 'ERROR') || 0 !== $proc->getExitCode()) { throw new ProcessFailedException($proc); } $result = new Binary($proc->getOutput(), $binary->getMimeType(), $binary->getFormat()); return $result; }
/** * @throws PhpCsFixerException */ public function run() { foreach ($this->levels as $level => $value) { if (true === $value) { $this->outputHandler->setTitle('Checking ' . strtoupper($level) . ' code style with PHP-CS-FIXER'); $this->output->write($this->outputHandler->getTitle()); $errors = array(); foreach ($this->files as $file) { $srcFile = preg_match($this->filesToAnalyze, $file); if (!$srcFile) { continue; } $processBuilder = new ProcessBuilder(array('php', 'bin/php-cs-fixer', '--dry-run', 'fix', $file, '--level=' . $level)); $phpCsFixer = $processBuilder->getProcess(); $phpCsFixer->run(); if (false === $phpCsFixer->isSuccessful()) { $errors[] = $phpCsFixer->getOutput(); } } if ($errors) { $this->output->writeln(BadJobLogo::paint()); throw new PhpCsFixerException(implode('', $errors)); } $this->output->writeln($this->outputHandler->getSuccessfulStepMessage()); } } }
/** * {@inheritdoc} */ public function analyze($analyzedFileName = null) { $result = new \SCQAT\Result(); $processBuilder = new ProcessBuilder(array($this->language->configuration["command"], $this->context->vendorDirectory . "bin/php-cs-fixer", "--level=psr2", "--dry-run", "--verbose", "fix", $analyzedFileName)); $process = $processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { $result->isSuccess = false; $result->value = "KO"; $description = ""; $outputLines = explode("\n", trim($process->getOutput())); foreach ($outputLines as $line) { // remove all output useless lines if (strpos($line, $analyzedFileName) !== false) { // remove filename and useles chars to just keep fixers violated $description = trim(substr($line, strpos($line, $analyzedFileName) + strlen($analyzedFileName)), " ()"); } } $result->description = "Triggered fixers : " . $description; } else { $result->isSuccess = true; $result->value = "OK"; } return $result; }
protected function runCommand($cmd) { $builder = new ProcessBuilder($cmd); $process = $builder->getProcess(); $process->run(); return $process->getOutput(); }
/** * {@inheritDoc} */ public function format($string) { static $format = <<<EOF package main import "fmt" import "github.com/russross/blackfriday" func main() { input := []byte("%s") output := blackfriday.MarkdownCommon(input) fmt.Printf(string(output[:])) } EOF; $input = tempnam(sys_get_temp_dir(), 'fabricius_blackfriday'); $input .= '.go'; file_put_contents($input, sprintf($format, addcslashes($string, "\n\""))); $pb = new ProcessBuilder(array($this->goBin, 'run', $input)); $proc = $pb->getProcess(); $code = $proc->run(); unlink($input); if (0 !== $code) { $message = sprintf("An error occurred while running:\n%s", $proc->getCommandLine()); $errorOutput = $proc->getErrorOutput(); if (!empty($errorOutput)) { $message .= "\n\nError Output:\n" . str_replace("\r", '', $errorOutput); } $output = $proc->getOutput(); if (!empty($output)) { $message .= "\n\nOutput:\n" . str_replace("\r", '', $output); } throw new RuntimeException($message); } return $proc->getOutput(); }
/** * @param string $file * * @return Process */ private function execute($file) { $processBuilder = new ProcessBuilder(['php', '-l', $file]); $process = $processBuilder->getProcess(); $process->run(); return $process; }
/** * @param string $file * @param string $standard * * @return Process */ private function execute($file, $standard) { $processBuilder = new ProcessBuilder(['php', $this->toolPathFinder->find('phpcs'), '--standard=' . $standard, $file]); $process = $processBuilder->getProcess(); $process->run(); return $process; }
protected function execute(InputInterface $input, OutputInterface $output) { // Direct access to the Container. /** @var Kengrabber $kg */ $kg = $this->getApplication()->getContainer(); $output->writeln("Build everything..."); $kg['monolog']->addDebug("Build everything..."); $commands = array("videolist:grab", "videolist:download", "cleanup", "verify", "render"); foreach ($commands as $command) { $builder = new ProcessBuilder(array("php", $_SERVER["SCRIPT_FILENAME"], $command)); if ($kg['debug'] === true) { $builder->add("--debug"); } $process = $builder->getProcess(); $process->setTimeout(0); $process->run(function ($type, $buffer) use($kg, $output) { if (Process::ERR === $type) { $output->write("<error>{$buffer}</error>"); } else { $output->write($buffer); } }); } $output->writeln("<info>Finished building...</info>"); }
/** * @throws InvalidCodingStandardException */ public function run() { $this->outputHandler->setTitle('Checking code style with PHPCS'); $this->output->write($this->outputHandler->getTitle()); foreach ($this->files as $file) { if (!preg_match($this->neddle, $file)) { continue; } $oldPath = getcwd(); $file = $oldPath . '/' . $file; chdir(__DIR__ . '/../../../../../../../'); $processBuilder = new ProcessBuilder(array('php', 'bin/phpcs', '--standard=' . self::STANDARD . '', $file)); /** @var Process $phpCs */ $phpCs = $processBuilder->getProcess(); $phpCs->run(); if (false === $phpCs->isSuccessful()) { $this->outputHandler->setError($phpCs->getOutput()); $this->output->writeln($this->outputHandler->getError()); $this->output->writeln(BadJobLogo::paint()); throw new InvalidCodingStandardException(); } chdir($oldPath); } $this->output->writeln($this->outputHandler->getSuccessfulStepMessage()); }
protected function runSampleDataInstaller() { $installationArgs = $this->config->getArray('installation_args'); $processBuilder = new ProcessBuilder(['php', 'bin/magento', 'sampledata:deploy']); if (!OperatingSystem::isWindows()) { $processBuilder->setPrefix('/usr/bin/env'); } $process = $processBuilder->getProcess(); $process->setTimeout(86400); $process->start(); $process->wait(function ($type, $buffer) { $this->output->write($buffer, false); }); // @TODO Refactor code duplication if (!OperatingSystem::isWindows()) { $processBuilder->setPrefix('/usr/bin/env'); } $processBuilder = new ProcessBuilder(array('php', 'bin/magento', 'setup:upgrade')); $process = $processBuilder->getProcess(); $process->setTimeout(86400); $process->start(); $process->wait(function ($type, $buffer) { $this->output->write($buffer, false); }); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $learning = $input->hasOption('learning') ? $input->getOption('learning') : false; $address = $input->getArgument('address'); if (false === strpos($address, ':')) { $address = sprintf('%s:8088', $address); } $finder = new PhpExecutableFinder(); if (false === ($binary = $finder->find())) { $io->error($this->trans('commands.server.errors.binary')); return; } $router = $this->getRouterPath(); $cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router); if ($learning) { $io->commentBlock($cli); } $io->success(sprintf($this->trans('commands.server.messages.executing'), $binary)); $processBuilder = new ProcessBuilder(explode(' ', $cli)); $process = $processBuilder->getProcess(); $process->setWorkingDirectory($this->get('site')->getRoot()); $process->setTty('true'); $process->run(); if (!$process->isSuccessful()) { $io->error($process->getErrorOutput()); } }
/** * Execute the job. * * @return void */ public function handle() { echo "Run task: #" . $this->job_id, "\n"; $task = Tasks::find($this->job_id); $task->status = Tasks::RUN; $task->save(); $client = new \Hoa\Websocket\Client(new \Hoa\Socket\Client('tcp://127.0.0.1:8889')); $client->setHost('127.0.0.1'); $client->connect(); $client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::RUN])])); $builder = new ProcessBuilder(); $builder->setPrefix('ansible-playbook'); $builder->setArguments(["-i", "inv" . $this->job_id, "yml" . $this->job_id]); $builder->setWorkingDirectory(storage_path("roles")); $process = $builder->getProcess(); $process->run(); //echo $process->getOutput() . "\n"; $client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::FINISH])])); $client->close(); $task->status = Tasks::FINISH; $task->content = file_get_contents(storage_path("tmp/log" . $this->job_id . ".txt")); $task->save(); unlink(storage_path("roles/yml" . $this->job_id)); unlink(storage_path("roles/inv" . $this->job_id)); unlink(storage_path("tmp/log" . $this->job_id . ".txt")); echo "End task: #" . $this->job_id, "\n"; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $database = $input->getArgument('database'); $file = $input->getOption('file'); $learning = $input->hasOption('learning') ? $input->getOption('learning') : false; $databaseConnection = $this->resolveConnection($io, $database); if (!$file) { $io->error($this->trans('commands.database.restore.messages.no-file')); return; } if ($databaseConnection['driver'] == 'mysql') { $command = sprintf('mysql --user=%s --password=%s --host=%s --port=%s %s < %s', $databaseConnection['username'], $databaseConnection['password'], $databaseConnection['host'], $databaseConnection['port'], $databaseConnection['database'], $file); } elseif ($databaseConnection['driver'] == 'pgsql') { $command = sprintf('PGPASSWORD="******" psql -w -U %s -h %s -p %s -d %s -f %s', $databaseConnection['password'], $databaseConnection['username'], $databaseConnection['host'], $databaseConnection['port'], $databaseConnection['database'], $file); } if ($learning) { $io->commentBlock($command); } $processBuilder = new ProcessBuilder(['-v']); $process = $processBuilder->getProcess(); $process->setWorkingDirectory($this->getDrupalHelper()->getRoot()); $process->setTty('true'); $process->setCommandLine($command); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } $io->success(sprintf('%s %s', $this->trans('commands.database.restore.messages.success'), $file)); }
/** * @throws PHPMDViolationsException */ public function run() { $this->outputHandler->setTitle('Checking code mess with PHPMD'); $this->output->write($this->outputHandler->getTitle()); $errors = []; foreach ($this->files as $file) { if (!preg_match($this->needle, $file)) { continue; } $processBuilder = new ProcessBuilder(array('php', 'bin/phpmd', $file, 'text', 'PmdRules.xml', '--minimumpriority', 1)); $process = $processBuilder->getProcess(); $process->run(); if (false === $process->isSuccessful()) { $errors[] = $process->getOutput(); } } $errors = array_filter($errors, function ($var) { return !is_null($var); }); if ($errors) { $this->output->writeln(BadJobLogo::paint()); throw new PHPMDViolationsException(implode('', $errors)); } $this->output->writeln($this->outputHandler->getSuccessfulStepMessage()); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $learning = $input->hasOption('learning') ? $input->getOption('learning') : false; $address = $this->validatePort($input->getArgument('address')); $finder = new PhpExecutableFinder(); if (false === ($binary = $finder->find())) { $io->error($this->trans('commands.server.errors.binary')); return; } $router = $this->getRouterPath(); $cli = sprintf('%s %s %s %s', $binary, '-S', $address, $router); if ($learning) { $io->commentBlock($cli); } $io->success(sprintf($this->trans('commands.server.messages.executing'), $binary)); $processBuilder = new ProcessBuilder(explode(' ', $cli)); $process = $processBuilder->getProcess(); $process->setWorkingDirectory($this->appRoot); if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) { $process->setTty('true'); } else { $process->setTimeout(null); } $process->run(); if (!$process->isSuccessful()) { $io->error($process->getErrorOutput()); } }
/** * Compresses a string. * * @param string $content The content to compress * @param string $type The type of content, either "js" or "css" * @param array $options An indexed array of additional options * * @return string The compressed content */ protected function compress($content, $type, $options = array()) { $pb = new ProcessBuilder(array($this->javaPath, '-jar', $this->jarPath)); foreach ($options as $option) { $pb->add($option); } if (null !== $this->charset) { $pb->add('--charset')->add($this->charset); } if (null !== $this->lineBreak) { $pb->add('--line-break')->add($this->lineBreak); } // input and output files $tempDir = realpath(sys_get_temp_dir()); $input = tempnam($tempDir, 'YUI-IN-'); $output = tempnam($tempDir, 'YUI-OUT-'); file_put_contents($input, $content); $pb->add('-o')->add($output)->add('--type')->add($type)->add($input); $proc = $pb->getProcess(); $code = $proc->run(); unlink($input); if (0 < $code) { if (file_exists($output)) { unlink($output); } throw FilterException::fromProcess($proc)->setInput($content); } if (!file_exists($output)) { throw new \RuntimeException('Error creating output file.'); } $retval = file_get_contents($output); unlink($output); return $retval; }
/** * Compresses a string. * * @param string $content The content to compress * @param string $type The type of content, either "js" or "css" * @param array $options An indexed array of additional options * * @return string The compressed content */ protected function compress($content, $type, $options = array()) { $pb = new ProcessBuilder(array($this->javaPath, '-jar', $this->jarPath)); foreach ($options as $option) { $pb->add($option); } if (null !== $this->charset) { $pb->add('--charset')->add($this->charset); } if (null !== $this->lineBreak) { $pb->add('--line-break')->add($this->lineBreak); } // input and output files $tempDir = realpath(sys_get_temp_dir()); $hash = substr(sha1(time() . rand(11111, 99999)), 0, 7); $input = $tempDir . DIRECTORY_SEPARATOR . $hash . '.' . $type; $output = $tempDir . DIRECTORY_SEPARATOR . $hash . '-min.' . $type; file_put_contents($input, $content); $pb->add('-o')->add($output)->add($input); $proc = $pb->getProcess(); $code = $proc->run(); unlink($input); if (0 < $code) { if (file_exists($output)) { unlink($output); } throw FilterException::fromProcess($proc)->setInput($content); } elseif (!file_exists($output)) { throw new \RuntimeException('Error creating output file.'); } $retval = file_get_contents($output); unlink($output); return $retval; }
/** * @inheritdoc * * @throws \Exception * If $mustRun is enabled and the command fails. */ public function execute(array $args, $dir = null, $mustRun = false, $quiet = true) { $builder = new ProcessBuilder($args); $process = $builder->getProcess(); // The default timeout is 1 minute. Increase it to 1 hour. $process->setTimeout(3600); if ($dir) { $process->setWorkingDirectory($dir); } if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $this->output->writeln("Running command: <info>" . $process->getCommandLine() . "</info>"); } try { $process->mustRun($quiet ? null : function ($type, $buffer) { $indent = ' '; $this->output->writeln($indent . str_replace("\n", "\n{$indent}", trim($buffer))); }); } catch (ProcessFailedException $e) { if (!$mustRun) { return false; } // The default for ProcessFailedException is to print the entire // STDOUT and STDERR. But if $quiet is disabled, then the user will // have already seen the command's output. So we need to re-throw // the exception with a much shorter message. $message = "The command failed with the exit code: " . $process->getExitCode(); $message .= "\n\nFull command: " . $process->getCommandLine(); if ($quiet) { $message .= "\n\nError output:\n" . $process->getErrorOutput(); } throw new \Exception($message); } $output = $process->getOutput(); return $output ? rtrim($output) : true; }
function execute($argv = array()) { $builder = new ProcessBuilder(); $builder->add($this->executable); if (@$argv[0] instanceof Response) { $builder->setInput(array_shift($argv)->getOutput()); } else { if (is_array(@$argv[0])) { $flags = array_shift($argv); foreach ($flags as $flag => $value) { $builder->add((strlen($flag) > 1 ? "--" : "-") . $flag); $value === true or $builder->add($value); } } } foreach ($argv as $a) { $builder->add($a); } $process = $builder->getProcess(); $process->run(); if (!$process->isSuccessful()) { $status = $process->getExitCode(); $commandLine = $process->getCommandLine(); throw new ErrorException("Command [{$commandLine}] failed with status [{$status}].", $status, $process->getErrorOutput()); } return new Response($process->getOutput(), $process->getErrorOutput()); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $database = $input->getArgument('database'); $file = $input->getOption('file'); $learning = $input->hasOption('learning') ? $input->getOption('learning') : false; $databaseConnection = $this->resolveConnection($io, $database); if (!$file) { $date = new \DateTime(); $file = sprintf('%s/%s-%s.sql', $this->getSite()->getSiteRoot(), $databaseConnection['database'], $date->format('Y-m-d-h-i-s')); } $command = sprintf('mysqldump --user=%s --password=%s --host=%s --port=%s %s > %s', $databaseConnection['username'], $databaseConnection['password'], $databaseConnection['host'], $databaseConnection['port'], $databaseConnection['database'], $file); if ($learning) { $io->commentBlock($command); } $processBuilder = new ProcessBuilder(['–lock-all-tables']); $process = $processBuilder->getProcess(); $process->setTty('true'); $process->setCommandLine($command); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } $io->success(sprintf('%s %s', $this->trans('commands.database.dump.messages.success'), $file)); }
/** * Creates the given process * * @throws \Exception */ private function startProcess(OutputInterface $output) { $arguments = $this->resolveProcessArgs(); $name = sha1(serialize($arguments)); if ($this->background->hasProcess($name)) { throw new \RuntimeException("Service is already running."); } $builder = new ProcessBuilder($arguments); if ($this->hasParameter('cwd')) { $builder->setWorkingDirectory($this->getParameter('cwd')); } $process = $builder->getProcess(); if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) { $output->writeln($process->getCommandLine()); } if ($this->hasParameter('output')) { $append = $this->hasParameter('append') && $this->getParameter('append') ? 'a' : 'w'; $stream = fopen($this->getParameter('output'), $append); $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, true); } $process->start(function ($type, $buffer) use($output) { $output->write($buffer); }); $this->background->addProcess($name, $process); if (!in_array($process->getExitCode(), $this->getParameter('successCodes'))) { throw new TaskRuntimeException($this->getName(), $process->getErrorOutput()); } }
/** * Checks if the render check commands returns "[OK]" */ public function testRenderCheckOk() { $pb = new ProcessBuilder(); $pb->setWorkingDirectory(realpath(__DIR__ . '\\..\\..\\..'))->setArguments(['php', 'bin/console', 'render:check']); $out = $pb->getProcess()->mustRun()->getOutput(); $this->assertContains('[OK]', $out); }