I'm trying to put the console into "raw" mode in Java. I understand this will only work on UNIX.
I'm using the command stty raw
If I type the command into the terminal directly, it does what it's supposed to do. In Java, I try to set the mode like this:
Runtime.getRuntime().exec("stty raw");
But the terminal does not go into raw mode.
I have a feeling this is because Java is just executing the command in a virtual terminal in the background or something, rather than the active terminal. Is there a way to do this?
Since the JVM redirects stdio/stdout/stderr, you might try something like this:
String[] cmd = {"/bin/sh", "-c", "stty raw </dev/tty"};
Runtime.getRuntime().exec(cmd);
Note that stty (usually) operates on stdin not stdout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With