且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

(UNIX /℃)QUOT; stty的:标准输入不是终端&Q​​UOT;使用系统时()函数

更新时间:2023-02-17 13:02:54

在标准输入是一个文件,它不是一个终端,所以设置的终端属性对的stty 的标准输入将无法工作。

When the standard input is a file, it isn't a terminal, so setting terminal attributes on stty's standard input won't work.

这听起来起初愚蠢的,但你可能会发现,你可以使用标准输出标准错误作为输入的stty 并调整终端。因此:

It sounds daft at first, but you will probably find that you can use either stdout or stderr as the input for stty and it will adjust the terminal. Therefore:

system("stty cbreak -echo <&2");

很可能设置终端的特性。如果你有的stty A GNU版本,你也可以使用:

is likely to set the terminal characteristics. If you have a GNU version of stty, you could also use:

system("stty -F /dev/stderr cbreak -echo");

或替代的/ dev /标准输出的/ dev / tty的的/ dev /标准错误。你也可以使用任何这些命名设备代替&安培; 2 在第一个变种重定向

or substitute /dev/stdout or /dev/tty for /dev/stderr. You could also use any of the named devices instead of the &2 in the redirection in the first variant.