/** * 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(); }
/** * 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(); }
/** * 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 * @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(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $address = $input->getArgument('address') ?: $this->serverAddress; $output->writeln(sprintf("Server running on <info>%s</info>\n", $address)); $process = $this->processBuilder->setArguments([PHP_BINARY, '-S', $address])->setWorkingDirectory(ROOT . 'web/')->setTimeout(null)->getProcess(); $process->run(function ($type, $buffer) use($output, $input) { unset($type); if (!$input->getOption('quiet')) { $output->write($buffer); } }); }
/** * 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(); } }
/** * @return Process */ public function create() { $processBuilder = new ProcessBuilder(); $processBuilder->setPrefix('vendor/bin/behat'); $processBuilder->setArguments(['--init']); return $processBuilder->getProcess(); }
/** * 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"; }
public function testShouldSetArguments() { $pb = new ProcessBuilder(array('initial')); $pb->setArguments(array('second')); $proc = $pb->getProcess(); $this->assertContains("second", $proc->getCommandLine()); }
/** * 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); }
function it_does_not_do_anything_if_there_are_no_keywords(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); $processBuilder->setArguments(Argument::any())->shouldNotBeCalled(); $processBuilder->getProcess()->shouldNotBeCalled(); $context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('file1.php')))); $this->run($context)->shouldBeNull(); }
function it_does_not_do_anything_if_there_are_no_keywords(ProcessBuilder $processBuilder) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); $processBuilder->setArguments(Argument::any())->shouldNotBeCalled(); $processBuilder->getProcess()->shouldNotBeCalled(); $files = new FilesCollection(array(new SplFileInfo('file1.php'))); $this->run($files)->shouldBeNull(); }
public function testArrayPrefixesArePrependedToAllGeneratedProcess() { $pb = new ProcessBuilder(); $pb->setPrefix(array('/usr/bin/php', 'composer.phar')); $proc = $pb->setArguments(array('-v'))->getProcess(); if ('\\' === DIRECTORY_SEPARATOR) { $this->assertEquals('"/usr/bin/php" "composer.phar" "-v"', $proc->getCommandLine()); } else { $this->assertEquals("'/usr/bin/php' 'composer.phar' '-v'", $proc->getCommandLine()); } $proc = $pb->setArguments(array('-i'))->getProcess(); if ('\\' === DIRECTORY_SEPARATOR) { $this->assertEquals('"/usr/bin/php" "composer.phar" "-i"', $proc->getCommandLine()); } else { $this->assertEquals("'/usr/bin/php' 'composer.phar' '-i'", $proc->getCommandLine()); } }
/** * Create process object * * @param string $inputFile * * @throws \RuntimeException * * @return Process */ public function createProcess($inputFile) { if (!is_file($inputFile)) { throw new \RuntimeException('Input file does not exist'); } $arguments = array_values($this->arguments->toArray()); array_push($arguments, '-f', $inputFile); return $this->builder->setArguments($arguments)->getProcess(); }
/** * @return Process */ private function getProcess() { if (!$this->process) { $this->processBuilder->setPrefix($this->utilityCommands[$this->utility]); $this->processBuilder->setArguments(array_merge($this->utilityArguments[$this->utility], [$this->image])); $this->process = $this->processBuilder->getProcess(); } return $this->process; }
/** * @param $command * * @return string * @throws \GrumPHP\Exception\FileNotFoundException */ protected function generateHookCommand($command) { $executable = $this->paths()->getBinCommand('grumphp', true); $this->processBuilder->setArguments([$this->paths()->getRelativeProjectPath($executable), $command]); if ($configFile = $this->useExoticConfigFile()) { $this->processBuilder->add(sprintf('--config=%s', $configFile)); } return $this->processBuilder->getProcess()->getCommandLine(); }
protected function getProcess($drupal, $dsn) { $builder = new ProcessBuilder(); $builder->inheritEnvironmentVariables(true); $builder->setWorkingDirectory($drupal); $builder->setPrefix('php'); $builder->setArguments(array('-d sendmail_path=`which true`', $this->drush, 'site-install', 'standard', "--db-url={$dsn}", '-y')); $process = $builder->getProcess(); return $process; }
/** * {@inheritdoc} */ public function getProcessBuilder(array $arguments, $timeout = self::DEFAULT_PROCESS_TIMEOUT) { $builder = new ProcessBuilder(); $builder->setPrefix($this->getPhpBinary()); $builder->setWorkingDirectory($this->getCwd()); $builder->setArguments($arguments); $builder->setTimeout($timeout); $builder->inheritEnvironmentVariables(true); return $builder; }
function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); $process->run()->shouldBeCalled(); $process->isSuccessful()->willReturn(false); $process->getOutput()->shouldBeCalled(); $context->getFiles()->willReturn(new FilesCollection(array(new SplFileInfo('test.php')))); $this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($context); }
function it_throws_a_Runtime_Exception_when_a_mirror_image_could_not_be_generated(ProcessBuilder $processBuilder, Process $process) { $processBuilder->setPrefix(Argument::any())->shouldBeCalled(); $processBuilder->setArguments(Argument::any())->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); $process->start()->shouldBeCalled(); $process->isRunning()->shouldBeCalled(); $process->isSuccessful()->willReturn(false); $process->getErrorOutput()->shouldBeCalled(); $this->shouldThrow('Symfony\\Component\\Process\\Exception\\RuntimeException')->duringReflect(); }
public function convert($imageUrl, $targetFilename, $targetFormat = 'png') { $export = sprintf('--export-%s=%s', $targetFormat, $targetFilename); $process = new XProcess($this->getContainer(), $this->getContainer()->getParameter('exec.inkscape')); $app = $process->getApplication(); $builder = new ProcessBuilder(); $builder->setPrefix($app); $arguments = ['--export-background=white', '--without-gui', $imageUrl, $export]; $cmd = $builder->setArguments($arguments)->getProcess()->getCommandLine(); return $process->run($cmd); }
/** * Constructs the proccess * * @param string $cmd command to be executed */ public function __construct($cmd) { $this->builder = new ProcessBuilder(); // Inherit environment variables from Host operating system $this->builder->inheritEnvironmentVariables(); $arguments = explode(' ', $cmd); // Environment variables could be passed as per *nix command line (FLAG)=(VALUE) pairs foreach ($arguments as $key => $argument) { if (preg_match('/([A-Z][A-Z0-9_-]+)=(.*)/', $argument, $matches)) { $this->builder->setEnv($matches[1], $matches[2]); unset($arguments[$key]); // Unset it from arguments list since we do not want it in proccess (otherwise command not found is given) } else { // Break if first non-environment argument is found, since after that everything is either command or option break; } } $this->builder->setArguments($arguments); $this->symfonyProcess = $this->builder->getProcess(); }
/** * Run the input and output through the vagrant machine * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return integer */ public function run(InputInterface $input, OutputInterface $output) { $builder = new ProcessBuilder(); $builder->setPrefix('breeze'); $builder->setArguments(array_slice($_SERVER['argv'], 1)); $script = $builder->getProcess()->getCommandLine(); // change to the root directory chdir(breeze_app_path()); // build the ssh command $ssh = $this->setEnvironmentCommand() . " vagrant ssh -c \"cat <<PROXY | sh" . PHP_EOL . $script . PHP_EOL . "PROXY\" -- -o StrictHostKeyChecking=no -o ForwardAgent=yes"; return passthru($ssh); }
/** * Constructs a configured Process instance * * @param string $targets space separated list of targets * @param PhingOptions $options * * @return Process */ private function createProcessInstance($targets, PhingOptions $options) { $builder = new ProcessBuilder(); $builder->setPrefix($this->options->getPhingBin()); $builder->setArguments($options->toArgumentsArray()); foreach (explode(' ', $targets) as $target) { if (strlen(trim($target))) { $builder->add(trim($target)); } } return $builder->getProcess(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $query = $input->getArgument('query'); $database = $input->getArgument('database'); $learning = $input->getOption('learning'); $databaseConnection = $this->resolveConnection($io, $database); $connection = sprintf('%s -A --database=%s --user=%s --password=%s --host=%s --port=%s', $databaseConnection['driver'], $databaseConnection['database'], $databaseConnection['username'], $databaseConnection['password'], $databaseConnection['host'], $databaseConnection['port']); $args = explode(' ', $connection); $args[] = sprintf('--execute=%s', $query); $opts = ["quick", "debug", "html", "xml", "raw", "vertical", "batch"]; array_walk($opts, function ($opt) use($input, &$args) { if ($input->getOption($opt)) { switch ($opt) { case "quick": $args[] = "--quick"; break; case "debug": $args[] = "-T"; break; case "html": $args[] = "-H"; break; case "xml": $args[] = "-X"; break; case "raw": $args[] = "--raw"; break; case "vertical": $args[] = "-E"; break; case "batch": $args[] = "--batch"; break; } } }); if ($learning) { $io->commentBlock(implode(" ", $args)); } $processBuilder = new ProcessBuilder([]); $processBuilder->setArguments($args); $process = $processBuilder->getProcess(); $process->setTty('true'); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } return 0; }
function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process) { $processBuilder->add('--config=default')->shouldBeCalled(); $processBuilder->add('--verbose')->shouldBeCalled(); $processBuilder->add('fix')->shouldBeCalled(); $processBuilder->add('file1.php')->shouldBeCalled(); $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); $process->getOutput()->shouldBeCalled(); $process->run()->shouldBeCalled(); $process->isSuccessful()->willReturn(false); $files = new FilesCollection(array(new SplFileInfo('file1.php'))); $this->shouldThrow('GrumPHP\\Exception\\RuntimeException')->duringRun($files); }
/** * Get the path to the php executable * * Attempt auto discovery via 'which php' if null * * @return string */ public function getPhpBin() { if ($this->phpBin === null) { $builder = new ProcessBuilder(); $builder->setPrefix('which'); $builder->setArguments(array('php')); $process = $builder->getProcess(); $process->run(); if ($process->getExitCodeText() == 'OK') { $this->phpBin = trim($process->getOutput()); } } return $this->phpBin; }
/** * Creates process with process builder and executes it. * * @param null $callback * @return int|string */ protected function runProcess($callback) { $process = $this->processBuilder->setArguments($this->prepareArguments())->getProcess(); // exitcode $result = $process->run($callback); // text-mode if (null === $callback) { $result = $process->getOutput(); if (false === $process->isSuccessful()) { $process->getErrorOutput(); } } return $result; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $message = $this->getMessageHelper(); $database = $input->getArgument('database'); $connection = $this->resolveConnection($message, $database); $message->showMessage($output, sprintf($this->trans('commands.database.client.messages.executing'), $connection)); $processBuilder = new ProcessBuilder([]); $processBuilder->setArguments(explode(' ', $connection)); $process = $processBuilder->getProcess(); $process->setTty('true'); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException($process->getErrorOutput()); } }
/** * @inheritdoc */ public function create($arguments = array()) { if (null === $this->binary) { throw new InvalidArgumentException('No binary set'); } if (!is_array($arguments)) { $arguments = array($arguments); } if (static::$emulateSfLTS) { array_unshift($arguments, $this->binary); return ProcessBuilder::create($arguments)->setTimeout($this->timeout)->getProcess(); } else { return $this->builder->setArguments($arguments)->getProcess(); } }