setInput() public method

This content will be passed to the underlying process standard input.
public setInput ( resource | scalar | Traversable | null $input ) : self
$input resource | scalar | Traversable | null The content
return self The current Process instance
示例#1
0
 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;
 }
 /**
  * @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());
 }
 /**
  * @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();
 }
 /**
  * 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());
 }
 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";
     }
 }
 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();
 }
 /**
  * @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());
     }
 }
 /**
  * @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
0
 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;
 }
 /**
  * @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
0
 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
0
 /**
  * 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
0
 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
0
 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
0
 /**
  * @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();
 }