Skip to content

Instantly share code, notes, and snippets.

@MattKetmo
Created September 7, 2012 11:46
Show Gist options
  • Save MattKetmo/3665488 to your computer and use it in GitHub Desktop.
Save MattKetmo/3665488 to your computer and use it in GitHub Desktop.
[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>');
}
}
@AhmedSamy
Copy link

Thanks

@mxschons
Copy link

Nice! Thank you :)

@zelding
Copy link

zelding commented Aug 6, 2018

cool, thx!

@des1roer
Copy link

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment