[英]Java Program not taking the Piped input
I have to work with a Java program which takes 2 user inputs like this: 我必须使用需要2个用户输入的Java程序,如下所示:
Enter username:
Enter password:
So I thought of sending it like 所以我想像这样发送
echo -e "myusername\npassword" | java javaprogram
and 和
java javaprogram < input.txt
Both didn't work. 两者都不起作用。
When I execute this command it's showing the error like this: 当我执行此命令时,它显示如下错误:
Enter userID: Enter password: Exception in thread "main" java.io.IOException: Unable to mask input in console. at..
I don't know the source code of this jar file. 我不知道这个jar文件的源代码。
What can be the reason for this ? 这可能是什么原因?
It's very possible that the program isn't reading the password from standard input, but from the terminal. 该程序很可能不是从标准输入中而是从终端读取密码。 There is a program called expect
, which is basically a language for scripting interactions with terminal programs. 有一个名为expect
的程序,它基本上是一种用于编写与终端程序交互的脚本的语言。
Take a look at http://expect.sourceforge.net/ 看看http://expect.sourceforge.net/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.