本文整理汇总了PHP中Symfony\Component\Process\Process::setInput方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::setInput方法的具体用法?PHP Process::setInput怎么用?PHP Process::setInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::setInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: kanjiToRomaji
public static function kanjiToRomaji($input, &$returnCode = '')
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return $input;
}
$japanese = "/([\\x{3000}-\\x{303f}\\x{3040}-\\x{309f}\\x{30a0}-\\x{30ff}\\x{ff00}-\\x{ff9f}\\x{4e00}-\\x{9faf}\\x{3400}-\\x{4dbf}])+/iu";
preg_match_all($japanese, $input, $matches);
if (empty($matches[0]) || !is_array($matches[0])) {
return $input;
}
$placeholders = ['in' => $matches[0], 'out' => []];
$uniq = uniqid();
$kakasi = 'kakasi -i euc -w | kakasi -i euc -Ha -Ka -Ja -Ea -ka';
$process = new Process($kakasi);
$words = implode($uniq, $placeholders['in']);
$convertedWords = mb_convert_encoding($words, 'eucjp', 'utf-8');
$process->setInput($convertedWords);
$process->run();
if (!$process->isSuccessful()) {
return IRCHelper::colorText('ERROR', IRCHelper::COLOR_RED) . ': can\'t run kakasi';
}
$romaji = $process->getOutput();
$placeholders['out'] = explode($uniq, $romaji);
$input = str_replace($placeholders['in'], $placeholders['out'], $input);
return $input;
}
示例2: execute
/**
* @return SystemData Process output.
*/
public function execute()
{
$process = new Process($this->command);
isset($this->input) && $process->setInput($this->input);
$process->run();
return new SystemData($process->getOutput(), $process->getErrorOutput(), $process->getExitCode());
}
示例3: iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode
/**
* @When I run phpspec and answer :answer when asked if I want to generate the code
*/
public function iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode($answer)
{
$command = sprintf('%s %s', $this->buildPhpSpecCmd(), 'run');
$env = array('SHELL_INTERACTIVE' => true, 'HOME' => $_SERVER['HOME']);
$this->process = $process = new Process($command);
$process->setEnv($env);
$process->setInput($answer);
$process->run();
}
示例4: check
/**
* Performs an obscure check with the given password
*
* @param string $password
* @throws ProcessFailedException
*/
public function check($password)
{
if (empty($password)) {
throw new InvalidArgumentException('The password cannot be empty');
}
$process = new Process($this->command);
$process->setInput($password);
$process->mustRun();
return $this->verifyOutput($process->getOutput());
}
示例5: renderNotebook
protected function renderNotebook($content)
{
$retval = null;
$process = new Process(__DIR__ . "/convertor.py");
$process->setInput($content);
$process->run();
if ($process->isSuccessful()) {
return $process->getOutput();
} else {
return "Parsing error";
}
}
示例6: doRender
protected function doRender()
{
$renderer = new DotGraphRenderer();
$dot_graph = $renderer->renderGraph($this->state_machine);
$process = new Process('dot -Tsvg');
$process->setInput($dot_graph);
$process->run();
if (!$process->isSuccessful()) {
throw new RuntimeError($process->getErrorOutput());
}
return $process->getOutput();
}
示例7: exists
/**
* @Given :class exists
*/
public function exists($class)
{
$descCmd = $this->buildCmd(sprintf('desc %s', $class));
$runCmd = $this->buildCmd('run');
$cmd = sprintf('%s && %s', $descCmd, $runCmd);
$process = new Process($cmd);
$process->setEnv(['SHELL_INTERACTIVE' => true]);
$process->setInput('Y');
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
}
示例8: iRunTheSpecFor
/**
* @When I run the spec for :fqcn
*/
public function iRunTheSpecFor($fqcn)
{
$cmd = $this->buildCmd(sprintf('run %s', $fqcn));
$cmd .= ' --format pretty';
$process = new Process($cmd);
$process->setEnv(['SHELL_INTERACTIVE' => true]);
$process->setInput('Y');
$process->run();
$this->lastOutput = $process->getOutput();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
}
示例9: processUrl
public function processUrl($url)
{
$result = $this->fetchUrl($url);
$fileContent = $result->getBody()->getContents();
$process = new Process('gpg --batch -sab');
$process->setInput($fileContent);
$process->run();
$error = $process->getErrorOutput();
$signatureStruct = new SignatureStruct();
$signatureStruct->setDownloadUrl($url);
$signatureStruct->setSignature($process->getOutput());
$signatureStruct->setSignatureType('gpg');
$signatureStruct->setSha256(hash('sha256', $fileContent));
//file_put_contents('test_archive.zip', $fileContent);
//file_put_contents('test_archive.zip.asc', $process->getOutput());
return $signatureStruct;
}
示例10: letsencrypt
/**
* @param string $script
* @param string $domain
* @param string $recoveryMail
* @param string $logsDir
*/
private function letsencrypt($script, $domain, $recoveryMail, $logsDir)
{
try {
$command = [];
// Script
$command[] = $script;
// We will use Symfony for the well-known challenge
$command[] = 'certonly';
$command[] = '--manual';
// Disable interaction
$command[] = '--manual-public-ip-logging-ok';
$command[] = '--agree-tos';
$command[] = '--renew-by-default';
// Recovery e-mail
$command[] = '--email';
$command[] = $recoveryMail;
// Logs directory
$command[] = '--logs-dir';
$command[] = $logsDir;
// Domain
$command[] = '--domain';
$command[] = $domain;
$process = new Process(implode(' ', $command));
$stdin = fopen('php://temp', 'w+');
$process->setInput($stdin);
$process->start(function ($type, $data) {
if (strpos($data, '.well-known/acme-challenge') !== false) {
preg_match('~\\.well-known/acme-challenge/([^ ]+) ~U', $data, $match);
var_dump($match);
}
});
$gotCert = false;
while ($process->isRunning()) {
/*if (! $gotCert && strpos($process->getOutput(), 'Press ENTER to continue') !== false) {
$gotCert = true;
// ...
fwrite($stdin, "\n");
}*/
}
} catch (\Exception $e) {
$this->handleError($e->getMessage(), $domain);
}
}
示例11: executeCommandStdin
protected function executeCommandStdin($command, $input = null)
{
$process = new Process($command);
$process->setTimeout(null);
if ($input) {
$process->setInput($input);
}
if ($this->workingDirectory) {
$process->setWorkingDirectory($this->workingDirectory);
}
$this->startTimer();
if ($this->isPrinted) {
$process->run(function ($type, $buffer) {
echo $buffer;
});
} else {
$process->run();
}
$this->stopTimer();
return new Result($this, $process->getExitCode(), $process->getOutput(), ['time' => $this->getExecutionTime()]);
}
示例12: save
/**
* Saves the current user's crontab.
*
* @return Crontab
* @throws \RuntimeException
*/
public function save()
{
$process = new Process('crontab');
$process->setInput($this->_rawTable);
$process->run();
if (!$process->isSuccessful()) {
$errorOutput = $process->getErrorOutput();
if ($errorOutput) {
throw new \RuntimeException(sprintf('There has been an error saving the crontab. Here\'s the output from the shell: %s', trim($errorOutput)));
}
throw new \RuntimeException('There has been an error saving the crontab.');
}
return $this;
}
示例13: testIteratorInput
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());
}
示例14: testNonBlockingNorClearingIteratorOutput
public function testNonBlockingNorClearingIteratorOutput()
{
$input = new InputStream();
$process = new Process(self::$phpBin . ' -r ' . escapeshellarg('fwrite(STDOUT, fread(STDIN, 3));'));
$process->setInput($input);
$process->start();
$output = array();
foreach ($process->getIterator(false, false) as $type => $data) {
$output[] = array($type, $data);
break;
}
$expectedOutput = array(array($process::OUT, ''));
$this->assertSame($expectedOutput, $output);
$input->write(123);
foreach ($process->getIterator(false, false) as $type => $data) {
if ('' !== $data) {
$output[] = array($type, $data);
}
}
$this->assertSame('123', $process->getOutput());
$this->assertFalse($process->isRunning());
$expectedOutput = array(array($process::OUT, ''), array($process::OUT, '123'));
$this->assertSame($expectedOutput, $output);
}
示例15: command
/**
* @param string $command
* @param string|string[] $filter
* @param array $options
* @param string $input
* @return string
* @throws CommandException
*/
public function command($command, $filter = null, array $options = array(), $input = null)
{
$parts = [$this->bin];
foreach ($this->rcOptions as $option) {
$parts[] = $option;
}
$filter = array_filter((array) $filter, 'trim');
if ($filter) {
foreach ($filter as $f) {
$parts[] = "( " . $f . " )";
}
}
$parts[] = $command;
foreach ($options as $param) {
$parts[] = $param;
}
$process = new Process($this->createCommandLine($parts));
if ($input) {
$process->setInput($input);
}
$process->run();
if (!$process->isSuccessful()) {
throw new CommandException($process);
}
return $process->getOutput();
}