Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirecting stdout causes stderr to be rendered without color #22007

Closed
zygoloid opened this issue Apr 15, 2024 · 2 comments
Closed

redirecting stdout causes stderr to be rendered without color #22007

zygoloid opened this issue Apr 15, 2024 · 2 comments

Comments

@zygoloid
Copy link
Contributor

Description of the bug:

Redirecting the stdout of bazel causes output sent to stderr to be rendered without color. Presumably bazel is only looking at isatty(1) and not at isatty(2). For example:

$ bazel info workspace
INFO: Invocation ID: ... # INFO in green
/home/zygoloid/workspace
$ bazel info workspace > /tmp/file
INFO: Invocation ID: ... # INFO *not* in green

Which category does this issue belong to?

CLI

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

$ bazel info workspace > /dev/null

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

release 7.1.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

$ strace -f bazel info workspace 2> >(grep TCGETS)
[pid 78660] ioctl(1, TCGETS, {c_iflag=BRKINT|ICRNL|IXON|IXANY|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD|HUPCL, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
[pid 78660] ioctl(2, TCGETS, 0x7ffcf3c74a10) = -1 ENOTTY (Inappropriate ioctl for device)
[pid 78660] ioctl(0, TCGETS, {c_iflag=BRKINT|ICRNL|IXON|IXANY|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD|HUPCL, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
[pid 78660] ioctl(0, TCGETS, {c_iflag=BRKINT|ICRNL|IXON|IXANY|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD|HUPCL, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
/home/zygoloid/workspace
$
$ strace -f bazel info workspace >/dev/null 2> >(grep TCGETS)
[pid 78697] ioctl(1, TCGETS, 0x7ffdfd30d110) = -1 ENOTTY (Inappropriate ioctl for device)
[pid 78697] ioctl(0, TCGETS, {c_iflag=BRKINT|ICRNL|IXON|IXANY|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD|HUPCL, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
[pid 78697] ioctl(0, TCGETS, {c_iflag=BRKINT|ICRNL|IXON|IXANY|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD|HUPCL, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
/home/zygoloid/workspace

bazel doesn't appear to look at the properties of stderr if stdout is redirected. However, if I only redirect stderr, bazel does correctly determine that it's not a TTY and doesn't color the output:

$ bazel info workspace 2> >(cat)
INFO: Invocation ID: ... # INFO not in green
/home/zygoloid/workspace
@zygoloid
Copy link
Contributor Author

Looks like this is being handled here:

return isatty(STDOUT_FILENO) && isatty(STDERR_FILENO);

Presumably separate flags would need to be computed to determine if stdout and stderr are TTYs.

@michajlo
Copy link
Contributor

This is intentional, see ac5a971. The TL;DR is it was causing confusing results.

@meisterT meisterT closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants