我正在使用 Symfony 控制台应用程序并尝试将 phpstan 的输出作为控制台命令的输入传递:
vendor/bin/phpstan analyse | bin/wte analyse
目前命令按预期运行,但如何将 phpstan 的输出传递到 bin/wte analysis
命令中?
// AnalyseCommand.php
final class AnalyseCommand extends Command
{
public const NAME = 'analyse';
/**
* @var SymfonyStyle
*/
private $symfonyStyle;
public function __construct(SymfonyStyle $symfonyStyle)
{
$this->symfonyStyle = $symfonyStyle;
parent::__construct();
}
public function execute(InputInterface $input, OutputInterface $output): int
{
// Get phpstan output in here.
return ShellCode::SUCCESS;
}
protected function configure(): void
{
$this->setName(self::NAME);
$this->setDescription('Find an error');
}
}
最佳答案
Symfony Console 没有任何处理标准输入的功能。但这不是必需的,因为您仍在使用 PHP 并且可以使用任何 native features .
public function execute(InputInterface $input, OutputInterface $output): int
{
$stdin = '';
while (!feof(STDIN)) {
$stdin .= fread(STDIN, 1024);
}
// do what you need with $stdin
}
关于php - 如何将命令的输出作为另一个命令的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63871805/