Linux stty:标准输入:设备的 ioctl 不合适

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4032790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:48:45  来源:igfitidea点击:

stty: standard input: Inappropriate ioctl for device

linuxbashperl

提问by Tree

perl script.pl --f1="t1" --f2="t2" --f3="t4" --f4 < /home/joe/a.txt 

script.pl

脚本文件

use Getopt::Long;
my ($f1, $f2, $f3, $f4) ;
GetOptions (
            'f1=s' => $f1,
            'f2=s' => $f2,
            'f3=s' => $f3,
            'f4' => $f4, );
if ($f1) {
    system('stty -echo');
    print "Password:";
    $pwd = <STDIN>;
    system('stty echo');
}

I got this error:

我收到此错误:

stty: standard input: Inappropriate ioctl for device
Password:stty: standard input: Inappropriate ioctl for device

What is this error? How do I resolve it?

这是什么错误?我该如何解决?

采纳答案by krico

I think the problem is you are reading from a redirected STDIN (because you <file.txt)

我认为问题在于您正在从重定向的 STDIN 中读取数据(因为您是 <file.txt)

$ perl -e 'system("stty -echo");' </tmp/foo
stty: standard input: Inappropriate ioctl for device

You should probably pass your file as a parameter to your script.

您可能应该将您的文件作为参数传递给您的脚本。

回答by NVRM

This message is painful, for users and programmers. It pollutes the STDOUT, sometimes 3 times in a row.

这个消息对于用户和程序员来说是痛苦的。它会污染 STDOUT,有时会连续 3 次。

There is no way to suppress it, even with messing with the stty -echostuff.

没有办法抑制它,即使与搞乱stty -echo的东西。

The sole solution is to redirect all the errors to/dev/null

唯一的解决方案是将所有错误重定向到/dev/null

./myscript <<< "some stuffs" 2> /dev/null
Or similary
echo "stuffs" | ./myscript 2> /dev/null

Annoying, and thus throw away all potential errors, which is not wanted at all.

烦人,因此扔掉所有潜在的错误,这是根本不想要的

not wanted at all.