MattKetmo
9/7/2012 - 11:46 AM

[Console] Write into stdout and stderr

[Console] Write into stdout and stderr

<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Testcase: app/console foo > std 2> err
 */
class FooCommand extends Command
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('foo')
        ;
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;

        $output->writeln('<info>standard message</info>');
        $errOutput->writeln('<error>error message</error>');
    }
}