作者:ronaldlunaramo
项目:webstor
public function testShouldSetArguments()
{
$pb = new ProcessBuilder(array('initial'));
$pb->setArguments(array('second'));
$proc = $pb->getProcess();
$this->assertContains("second", $proc->getCommandLine());
}
作者:sdieunido
项目:php-git-hook
/**
* @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());
}
作者:brul
项目:php-git-hook
/**
* @param string $file
*
* @return Process
*/
private function execute($file)
{
$processBuilder = new ProcessBuilder(['php', '-l', $file]);
$process = $processBuilder->getProcess();
$process->run();
return $process;
}
作者:noiseblee
项目:markdown-resum
public function filterDump(AssetInterface $asset)
{
$pb = new ProcessBuilder(array($this->pngoutBin));
if (null !== $this->color) {
$pb->add('-c' . $this->color);
}
if (null !== $this->filter) {
$pb->add('-f' . $this->filter);
}
if (null !== $this->strategy) {
$pb->add('-s' . $this->strategy);
}
if (null !== $this->blockSplitThreshold) {
$pb->add('-b' . $this->blockSplitThreshold);
}
$pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_pngout'));
file_put_contents($input, $asset->getContent());
$output = tempnam(sys_get_temp_dir(), 'assetic_pngout');
unlink($output);
$pb->add($output .= '.png');
$proc = $pb->getProcess();
$code = $proc->run();
if (0 < $code) {
unlink($input);
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent(file_get_contents($output));
unlink($input);
unlink($output);
}
作者:TYPO
项目:Sur
/**
* 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);
}
作者:mangareade
项目:laravel-ansibl
/**
* 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";
}
作者:engelj
项目:kexpgrabbe
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>");
}
作者:durgesh
项目:DrupalConsol
/**
* {@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="%s" 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));
}
作者:pierredu
项目:gush-bloc
protected function runCommand($cmd)
{
$builder = new ProcessBuilder($cmd);
$process = $builder->getProcess();
$process->run();
return $process->getOutput();
}
作者:ibonell
项目:DrupalConsol
/**
* {@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());
}
}
作者:ambroisemaupat
项目:intervention-reques
/**
* @param ImageSavedEvent $event
*/
public function onPngImageSaved(ImageSavedEvent $event)
{
if ($event->getImage()->mime() == "image/png" && $this->pngquantPath != "") {
$builder = new ProcessBuilder(array($this->pngquantPath, '-f', '--speed', '1', '-o', $event->getImageFile()->getPathname(), $event->getImageFile()->getPathname()));
$builder->getProcess()->run();
}
}
作者:dw25010078
项目:php-git-hook
public function run()
{
$this->outputHandler->setTitle(sprintf('Checking json code with %s', strtoupper('jsonlint')));
$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/jsonlint', $file));
$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 JsonLintViolationsException(implode('', $errors));
}
$this->output->writeln($this->outputHandler->getSuccessfulStepMessage());
}
作者:amini
项目:LiipImagineBundl
/**
* @param BinaryInterface $binary
*
* @throws ProcessFailedException
*
* @return BinaryInterface
*
* @see Implementation taken from Assetic\Filter\optipngFilter
*/
public function process(BinaryInterface $binary)
{
$type = strtolower($binary->getMimeType());
if (!in_array($type, array('image/png'))) {
return $binary;
}
if (false === ($input = tempnam(sys_get_temp_dir(), 'imagine_optipng'))) {
throw new \RuntimeException(sprintf('Temp file can not be created in "%s".', sys_get_temp_dir()));
}
$pb = new ProcessBuilder(array($this->optipngBin));
$pb->add('--o7');
$pb->add($input);
if ($binary instanceof FileBinaryInterface) {
copy($binary->getPath(), $input);
} else {
file_put_contents($input, $binary->getContent());
}
$proc = $pb->getProcess();
$proc->run();
if (false !== strpos($proc->getOutput(), 'ERROR') || 0 !== $proc->getExitCode()) {
unlink($input);
throw new ProcessFailedException($proc);
}
$result = new Binary(file_get_contents($input), $binary->getMimeType(), $binary->getFormat());
unlink($input);
return $result;
}
作者:kangko
项目:bld
/**
* 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());
}
}
作者:brul
项目:php-git-hook
/**
* @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;
}
作者:dw25010078
项目:php-git-hook
/**
* @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());
}
}
}
作者:cloriche
项目:SCQA
/**
* {@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;
}
作者:mnic
项目:DrupalConsol
/**
* {@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());
}
}
作者:etd-framewor
项目:Ghostscrip
/**
* Create process builder object
*
* @param array $arguments
*
* @return ProcessBuilder
*/
protected function createProcessBuilder(array $arguments = [])
{
$processBuilder = new ProcessBuilder($arguments);
$processBuilder->setPrefix($this->getOption('bin', self::DEFAULT_BINARY));
$processBuilder->addEnvironmentVariables($this->getOption('env', []));
return $processBuilder;
}
作者:Robert-Xi
项目:php-framework-benchmar
/**
* Run the asset through UglifyJs
*
* @see Assetic\Filter\FilterInterface::filterDump()
*/
public function filterDump(AssetInterface $asset)
{
$executables = array();
if ($this->nodeJsPath !== null) {
$executables[] = $this->nodeJsPath;
}
$executables[] = $this->uglifyCssPath;
$pb = new ProcessBuilder($executables);
if ($this->expandVars) {
$pb->add('--expand-vars');
}
if ($this->uglyComments) {
$pb->add('--ugly-comments');
}
if ($this->cuteComments) {
$pb->add('--cute-comments');
}
// input and output files
$input = tempnam(sys_get_temp_dir(), 'input');
file_put_contents($input, $asset->getContent());
$pb->add($input);
$proc = $pb->getProcess();
$code = $proc->run();
unlink($input);
if (127 === $code) {
throw new \RuntimeException('Path to node executable could not be resolved.');
}
if (0 < $code) {
throw FilterException::fromProcess($proc)->setInput($asset->getContent());
}
$asset->setContent($proc->getOutput());
}