简体   繁体   English

Java程序未采用管道输入

[英]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/

Have a look at expect which helps with programmed dialogue with interactive programs. 看一下期望值 ,它有助于与交互式程序进行编程对话。 Additionally, in case you want to know more about the source of the *.jar file you are using, you can decompile it. 此外,如果您想了解更多有关正在使用的* .jar文件的来源的信息,可以对其进行反编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM