本文整理汇总了PHP中Symfony\Component\Process\Process::setStdin方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::setStdin方法的具体用法?PHP Process::setStdin怎么用?PHP Process::setStdin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Process\Process
的用法示例。
在下文中一共展示了Process::setStdin方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
function render($context = null, $vars = array())
{
$options = $this->options;
$compress = @$options["compress"] ?: false;
$outputFile = tempnam(sys_get_temp_dir(), 'metatemplate_template_less_output');
$finder = new ExecutableFinder();
$bin = @$this->options["less_bin"] ?: self::DEFAULT_LESSC;
$cmd = $finder->find($bin);
if ($cmd === null) {
throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed.");
}
if ($compress) {
$cmd .= ' -x';
}
if (array_key_exists('include_path', $this->options)) {
$cmd .= sprintf('--include-path %s', escapeshellarg(join(PATH_SEPARATOR, (array) $this->options['include_path'])));
}
$cmd .= " --no-color - {$outputFile}";
$process = new Process($cmd);
$process->setStdin($this->getData());
if ($this->isFile()) {
$process->setWorkingDirectory(dirname($this->source));
}
$process->setEnv(array('PATH' => getenv("PATH")));
$process->run();
$content = @file_get_contents($outputFile);
@unlink($outputFile);
if (!$process->isSuccessful()) {
throw new \RuntimeException("{$cmd} returned an error: " . $process->getErrorOutput());
}
return $content;
}
示例2: transform
/**
* {@inheritdoc)
*/
public function transform(\Swift_Mime_Message $message)
{
$processor = new Process($this->getCommand());
$processor->setStdin($message->getBody());
$processor->run();
if ($processor->isSuccessful()) {
$message->addPart($processor->getOutput(), 'text/plain');
}
}
示例3: testProcessPipes
/**
* tests results from sub processes
*
* @dataProvider pipesCodeProvider
*/
public function testProcessPipes($expected, $code)
{
$p = new Process(sprintf('php -r \'%s\'', $code));
$p->setStdin($expected);
$p->run();
$this->assertSame($expected, $p->getOutput());
$this->assertSame($expected, $p->getErrorOutput());
$this->assertSame(0, $p->getExitCode());
}
示例4: pipe
/**
* Executes external command
*/
public function pipe($value, $command)
{
$process = new Process($command);
$process->setStdin($value);
$process->run();
if (!$process->isSuccessful()) {
return false;
}
return $process->getOutput();
}
示例5: render
function render($context = null, $vars = array())
{
$cmd = "/usr/bin/env uglifyjs";
$process = new Process($cmd);
$process->setStdin($this->data);
$process->run();
if (!$process->isSuccessful()) {
throw new \Exception("uglifyjs exited with an error: {$process->getErrorOutput()}");
}
return $process->getOutput();
}
示例6: testProcessPipes
/**
* tests results from sub processes
*
* @dataProvider pipesCodeProvider
*/
public function testProcessPipes($expected, $code)
{
if (strpos(PHP_OS, "WIN") === 0) {
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 and https://bugs.php.net/bug.php?id=51800');
}
$p = new Process(sprintf('php -r %s', escapeshellarg($code)));
$p->setStdin($expected);
$p->run();
$this->assertSame($expected, $p->getOutput());
$this->assertSame($expected, $p->getErrorOutput());
$this->assertSame(0, $p->getExitCode());
}
示例7: testProcessPipes
/**
* tests results from sub processes
*
* @dataProvider pipesCodeProvider
*/
public function testProcessPipes($expected, $code)
{
if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
$this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
}
$p = new Process(sprintf('php -r %s', escapeshellarg($code)));
$p->setStdin($expected);
$p->run();
$this->assertSame($expected, $p->getOutput());
$this->assertSame($expected, $p->getErrorOutput());
$this->assertSame(0, $p->getExitCode());
}
示例8: render
function render($context = null, $vars = array())
{
$finder = new ExecutableFinder();
$bin = @$this->options["coffee_bin"] ?: self::DEFAULT_COFFEE;
$cmd = $finder->find($bin);
if ($cmd === null) {
throw new \UnexpectedValueException("'{$bin}' executable was not found. Make sure it's installed.");
}
$cmd .= " -sc";
$process = new Process($cmd);
$process->setEnv(array('PATH' => @$_SERVER['PATH'] ?: join(PATH_SEPARATOR, array("/bin", "/sbin", "/usr/bin", "/usr/local/bin"))));
$process->setStdin($this->data);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException("coffee({$this->source}) returned an error:\n {$process->getErrorOutput()}");
}
return $process->getOutput();
}
示例9: executeCommand
public function executeCommand($command, $stdIn = null, $quiet = false)
{
$this->tty = $stdIn instanceof TTY;
$command = $this->decorator->decorateCommand($command, $this);
$this->process = $process = new Process($command, array_shift($this->workingDirectoriesStack));
$process->setTimeout(null);
if (null !== $stdIn) {
if ($this->tty) {
$process->setTty(true);
} else {
$process->setStdin($stdIn);
}
}
$output = $this->getOutput();
if ($output && $output->getVerbosity() >= $output::VERBOSITY_VERBOSE) {
$output->writeln(sprintf('$ %s', $command));
$start = true;
$prefix = ' ---> ';
$process->start(function ($type, $buffer) use($output, &$start, $prefix, $quiet) {
if ($start) {
$buffer = $prefix . $buffer;
$start = false;
}
if ($buffer[strlen($buffer) - 1] == "\n") {
$start = true;
$buffer = strtr(substr($buffer, 0, -1), ["\n" => "\n" . $prefix]) . "\n";
} else {
$buffer = strtr($buffer, ["\n" => "\n" . $prefix]);
}
$quiet || $output->write($buffer);
});
$process->wait();
} else {
$process->run();
}
if ($process->getExitCode() != 0) {
throw new ProcessFailedException($process);
}
return $process->getOutput();
}
示例10: setInput
public function setInput(Process $proc)
{
$proc->setStdin($this->resource);
}