@@ -373,3 +373,31 @@ of your commands to change their appearance::
373373 // ...
374374 }
375375 }
376+
377+ Writing to the error output
378+ ---------------------------
379+
380+ If you rely on the output of a command (e.g. by redirecting it to a file for later reuse),
381+ you may want to get only the relevant information outputted by the command, excluding progress
382+ bars, notes, warnings and other error messages which have, most of the time, no value for reuse.
383+
384+ For excluding irrelevant messages from the output, you need to make your command write them to the error
385+ output. Fortunately, the :class: `Symfony\\ Component\\ Console\\ Style\\ SymfonyStyle ` provides a convenient
386+ method to easily switch between both outputs:
387+ :method: `Symfony\\ Component\\ Console\\ Style\\ SymfonyStyle::getErrorStyle `.
388+ This method returns a new ``SymfonyStyle `` instance which makes use of the error output:
389+
390+ $io = new SymfonyStyle($input, $output);
391+
392+ // Write to the output
393+ $io->write('Reusable information');
394+
395+ // Write to the error output
396+ $io->getErrorStyle()->warning('Irrelevant warning');
397+
398+ .. note ::
399+
400+ If you created the original ``SymfonyStyle `` instance with an ``OutputInterface `` object that is
401+ not an instance of :class: `Symfony\\ Component\\ Console\\ Output\\ ConsoleOutputInterface `, using
402+ ``getErrorStyle() `` will return an instance which makes use of the normal output instead of
403+ the error one, as if you did not called the method.
0 commit comments