Skip to content

Instantly share code, notes, and snippets.

@welblaud
Forked from MattKetmo/FooCommand.php
Last active February 17, 2023 16:03
Show Gist options
  • Save welblaud/2fcb064abb5bb9bbb59f0df9c964b50d to your computer and use it in GitHub Desktop.
Save welblaud/2fcb064abb5bb9bbb59f0df9c964b50d to your computer and use it in GitHub Desktop.
Writing to stdout and stderr in Symfony app
<?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