Skip to content

console: Ansi stripped on stdout when stderr is redirected #38981

@cxj

Description

@cxj

Symfony version(s) affected: 5.1.8

Description
ANSI color is stripped (command behaves if run with --no-ansi flag) from standard output when standard error is redirected.

How to reproduce
Pick any console app that issues output with ANSI color, and in a POSIX shell such as sh or bash, redirect standard error, e.g.:

bin/console some:command 2> /dev/null

Possible Solution
I would guess the *_isatty() check is being done on both stdout and stderr file descriptors and if either is not a TTY, the ANSI flag is wrongly cleared for both. Solution would be to check and manage the 2 file streams or descriptors separately.

Additional context
Explicitly adding the --ansi flag makes it work, e.g.:
bin/console --ansi some:command 2> /dev/null
correctly outputs the stdout text, such as [OK] message, in ANSI color.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions