3 ms·
Allegedly System.console() but of course it's not actually the same and can be wrong in some important cases, leaving you with jni.
by tedunangst 7y ago
Allegedly System.console() but of course it's not actually the same and can be wrong in some important cases, leaving you with jni.
- marvy 7y agowhen 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.