0

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 ?

5
  • Did you try below? java javaprogram username password Commented Apr 6, 2018 at 12:27
  • 1
    @Srivignesh It's prompting for user input and not taking the command line arguments Commented Apr 6, 2018 at 12:29
  • jd-gui tool is a lightweight decompiler which will help in viewing the source code Commented Apr 6, 2018 at 12:31
  • "myusername\npassword\n" a newline on last line? Though that error is something else... Commented Apr 6, 2018 at 12:39
  • @JoopEggen echo appends a newline to its output. Commented Apr 6, 2018 at 12:57

2 Answers 2

3

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/

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.