Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute 'stty raw' command in same terminal?

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?

like image 893
Matt Avatar asked Dec 25 '10 21:12

Matt


1 Answers

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.

like image 194
Rick Sladkey Avatar answered Sep 25 '22 15:09

Rick Sladkey