On Mon, 29 Apr 2024 11:44:50 GMT, Jan Lahoda <jlah...@openjdk.org> wrote:

> Consider code like:
> 
> public class ConsoleTest {
>     public static void main(String... args) {
>         System.console().printf("Hello!");
>     }
> }
> 
> 
> When run as:
> 
> $ java ConsoleTest.java >/dev/null
> 
> 
> it prints `Hello!` to stderr, instead of to stdout (where it would be 
> redirected).
> 
> The proposed fix is to simply force the use of stdout. Sadly, this cannot be 
> done solely using JLine configuration, we actually need to change the JLine's 
> code for that.
> 
> The most tricky part is a test. There are two sub-tests, one effectively 
> testing a case where all of stdin/out/err are redirected, the other is 
> attempting to test the case where stdin is attached to a terminal, while 
> stdout is redirected. The second sub-test using a native functions to create 
> a pty and to attach to it, and should run in a separate VM, as it leaves the 
> VM attached to the terminal.

This pull request has now been integrated.

Changeset: f1509e00
Author:    Jan Lahoda <jlah...@openjdk.org>
URL:       
https://git.openjdk.org/jdk/commit/f1509e007d1538acfb1749f7fafc56be2affd2e6
Stats:     183 lines in 3 files changed: 180 ins; 0 del; 3 mod

8330998: System.console() writes to stderr when stdout is redirected

Reviewed-by: naoto

-------------

PR: https://git.openjdk.org/jdk/pull/18996

Reply via email to