在同一终端执行'stty raw'命令? [英] Execute 'stty raw' command in same terminal?

查看:993
本文介绍了在同一终端执行'stty raw'命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Java中将控制台置于原始模式。我理解这只能在UNIX上使用。

I'm trying to put the console into "raw" mode in Java. I understand this will only work on UNIX.

我使用命令 stty raw

如果我直接在终端输入命令,它会做它应该做的事情。在Java中,我尝试设置这样的模式:

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.

我有一种感觉,这是因为Java只是在后台的某个虚拟终端执行命令,而不是活动终端。

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?

推荐答案

由于JVM重定向stdio / stdout / stderr,所以你可以尝试这样:

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);

注意stty(通常)对stdin不是stdout操作。

Note that stty (usually) operates on stdin not stdout.

这篇关于在同一终端执行'stty raw'命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆