Prajwal
Prajwal

Reputation: 673

Java Program not taking the Piped input

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 ?

Upvotes: 0

Views: 75

Answers (2)

acoelhosantos
acoelhosantos

Reputation: 1589

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.

Upvotes: 2

Tripp Kinetics
Tripp Kinetics

Reputation: 5459

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/

Upvotes: 3

Related Questions