I have to work with a Java program which takes 2 user inputs like this:
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.
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.
Take a look at 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.