-
-
Save welblaud/2fcb064abb5bb9bbb59f0df9c964b50d to your computer and use it in GitHub Desktop.
Writing to stdout and stderr in Symfony app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment