RFR: 8330998: System.console() writes to stderr when stdout is redirected [v2]
Jan Lahoda
jlahoda at openjdk.org
Tue Apr 30 14:04:05 UTC 2024
On Mon, 29 Apr 2024 20:21:23 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
> > Of course the question is if it should write to stderr or /dev/tty like mechanism..
>
> I was wondering the same thing. My understanding of the definition of "console" is a bidirectional byte channel with a keyboard & screen on the other end. It has no concept of stdout vs. stderr. It just has a display (or in the old days, a printer).
>
> The function of a "shell" is to intermediate between one or more executing programs and the console. It figures out how & when to actually display on the console any stuff written to stdout and/or stderr by one of the programs it has launched.
>
> A program can also access its console (if any) directly by opening /dev/tty or whatever, thereby bypassing the shell.
>
> So I would think writing to something called "System.console()" from Java (which is a program) would have nothing to do with Java's stderr or stdout, except for a possible downstream interleaving with what the shell may also be writing to the console at the same time.
I tried a few programs, like `mc`, `top` and `htop`. When I redirect the stdout for them, they still write into it (and there's obviously nothing on the terminal, and there are escape sequences in the target file of the redirect). The only program I know from the top of my head that (AFAIK) bypasses stdin/stdout and reaches directly to the controlling terminal is `ssh` when reading passwords (for quite obvious very special reasons).
I.e. not trying to be too smart about output, and simply using stdout as other programs do seems consistent, and most useful - the output can then be used in pipes, etc.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/18996#issuecomment-2085419986
More information about the core-libs-dev
mailing list