【发布时间】:2016-06-01 11:44:21
【问题描述】:
在我的app/config/config.yml 中,我为独白添加了控制台处理程序:
monolog:
handlers:
console:
type: console
因此,当我传递详细程度标志 -vvv 时,一个命令会产生对独白的调用的输出,例如:
./bin/console text:hello k0pernikus -vvv
[2016-06-01 13:19:27] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". {"uid":"c1e943a"}
[2016-06-01 13:19:27] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". {"uid":"c1e943a"}
Ipsum lorem dolorem
Hello k0pernikus!
Ipsum lorem dolorem
现在我想通过 grep 获取第一行
/bin/console text:hello k0pernikus -vvv | grep DebugHandlersListener::configure
但我也得到了第二个 DEBUG:
[2016-06-01 13:21:17] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". {"uid":"9e84992"}
[2016-06-01 13:21:17] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". {"uid":"9e84992"}
我还注意到输出的行为很奇怪,因为我也无法重定向它:
./bin/console text:hello k0pernikus -vvv > fnord
[2016-06-01 13:22:13] event.DEBUG: Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". {"uid":"f21ef6f"}
[2016-06-01 13:22:13] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". {"uid":"f21ef6f"}
cat fnord
Ipsum lorem dolorem
Hello k0pernikus!
Ipsum lorem dolorem
这似乎是想要的行为,但我对如何处理详细输出有点困惑。我对所有台词都不感兴趣,只对其中之一感兴趣。
如何 grep 一行?
我的命令:
<?php
namespace Kopernikus\ApiBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* PlainTextHelloWorldCommand
**/
class PlainTextHelloWorldCommand extends Command
{
/**
*
*/
protected function configure()
{
$this
->setName('text:hello')
->addArgument('reciever', InputArgument::REQUIRED, 'Who do you want to greet?');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$reciever = $input->getArgument('reciever');
$output->writeln("Ipsum lorem dolorem");
$output->writeln("Hello {$reciever}!");
$output->writeln("Ipsum lorem dolorem");
}
}
【问题讨论】:
-
您可以检查详细程度并在此基础上编写输出,这对您来说是一个可能的解决方案(我可以发布代码来帮助解决这个问题)
-
@Rooneyl 我不想添加自定义输出。我想 grep 现有的详细输出。我想这更多地与 bash 如何处理不同的输出流有关。我宁愿不通过输出代码来解决这个问题。
标签: bash symfony grep command output