-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8330998: System.console() writes to stderr when stdout is redirected #18996
Conversation
👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into |
@lahodaj This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 30 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Left some minor suggestions.
BTW, should we file an issue at the JLine
project, not to redirect to stderr, or suggest a new config (sorry if it has already been taken care of)?
* @bug 8330998 | ||
* @summary Verify that even if the stdout is redirected java.io.Console will | ||
* use it for writing. | ||
* @run main RedirectedStdOut runRedirectAllTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@modules jdk.internal.le
is needed, as the test relies on it.
String testJDK = System.getProperty("test.jdk"); | ||
Path javaLauncher = Path.of(testJDK, "bin", "java"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could utilize ProcessTools
test library to start the test jdk process (applies to the other location as well)
I think it's a feature when System.console() actually writes to the tty if stdout is redirected. After all it's not System.out. 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 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. |
Totally reasonable. But the ssh example is telling - suppose for example someone wanted to implement something like ssh in Java. Would that person expect to be able to do what ssh does (accepting non-echoed passwords) by using In other words, what exactly is These questions are probably beyond the scope of this PR but you've got me curious :) |
The code to choose the output stream is quite elaborate, so I assume that is intentional. For new versions of JLine, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
/integrate |
Going to push as commit f1509e0.
Your commit was automatically rebased without conflicts. |
openjdk#18996 now allows us to test Console IO better.
Consider code like:
When run as:
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.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18996/head:pull/18996
$ git checkout pull/18996
Update a local copy of the PR:
$ git checkout pull/18996
$ git pull https://git.openjdk.org/jdk.git pull/18996/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18996
View PR using the GUI difftool:
$ git pr show -t 18996
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18996.diff
Webrev
Link to Webrev Comment