(UNIX /℃)QUOT; stty的:标准输入不是终端"使用系统时()函数 [英] (unix/C) "stty: stdin isn't a terminal" when using system() function
问题描述
我们正在阅读从标准输入一个文件到 file_buffer
,然后步入一个方法更多
。
We're reading a file from stdin into file_buffer
, and then stepping into a method more
.
当我们使用系统(stty的CBREAK -echo);
,输出打印的stty:标准输入不是终端,不设置我们的终端,我们要求的设置。
As soon as we use system("stty cbreak -echo");
, the output prints "stty: stdin isn't a terminal" and doesn't set our terminal to the settings we asked for.
这个问题只存在当我们使用标准的。如果我们用一个文件参数,该程序工作正常。 - 终端设置获取设置,并没有错误消息
This problem only exists when we use standard in. If we use a file argument, the program works fine -- the terminal settings get set, and there is no error message.
所以,这是好的: myprogram FILE1.TXT
但是,这并不: myprogram< FILE1.TXT
无论哪种方式被使用在所有前的内容被读入 file_buffer
。到底是什么错误使用stty的,如果我们采取从标准输入??
Either way the contents are being read into file_buffer
before being used at all. What the heck is wrong with using stty if we're taking input from stdin??
推荐答案
在标准输入是一个文件,它不是一个终端,所以设置的终端属性对的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.
这篇关于(UNIX /℃)QUOT; stty的:标准输入不是终端&QUOT;使用系统时()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!