3 ms·
when would console() be wrong?
by marvy 7y ago
when would console() be wrong?
- skissane 7y agoSee this code: https://github.com/openjdk/jdk/blob/39c023612dbdd1016ad24b60fdef464bf21d1016/src/java.base/unix/native/libjava/Console_md.c#L38 https://github.com/openjdk/jdk/blob/39c023612dbdd1016ad24b60... It only works when isatty() returns true on both stdin and stdout. If you redirect stdin from a file, but stdout still goes to tty, isatty() on stdout will return true, but System.console() will return null. If you are using isatty() on stdout to decide whether to display fancy output, then whether stdin is a tty or not isn't relevant. So in that scenario System.console() doesn't do what you want.
- marvy 7y agoThat makes sense, thanks! So it's a bit over-cautious.