3

I'm using a compiled Java file which takes a filename as a parameter and then asks for a username and password (via user input). I am trying to automate this from a shell script, but am running into problems. I'm unable to access the java code, which is why I am having trouble.
So the code is called the following way

java javaprogram /home/user/securityfile

So, you pass the file, and then it asks you for username and password. After entering those, it's done.

Now, I have tried to put the user input into a file and pass it in, but I get an error.

java javaprogram /home/user/securityfile < userinputfile

userinput file contains the following text (First line is the username, second line is the password):

MattSmith
MSpassword136

Does anyone have any ideas? Maybe I am doing it wrong?

Here is the error message:

Exception in thread "main" java.lang.NullPointerException at ilex.util.UserAuthFile.main(UserAuthFile.java:297) 

Thanks

15
  • How is this a programming question? Commented Apr 16, 2018 at 21:37
  • 1
    If you just want to figure out what the Java program is doing, perhaps try decompiling it? Or, since it sounds like this is a Linux system, you could try using strace to see exactly how it's interacting with the console. Note that any mechanism to read a password securely on the console won't work with a pipe; you'll probably need a pty instead. Commented Apr 16, 2018 at 21:56
  • 1
    Try (echo "user"; sleep 1; echo "password") | java javaprogram /home/user/securityfile. If that works you can refactor to read from file without too much work. Commented Apr 16, 2018 at 22:46
  • 1
    May be that app will never read from System.in since it requires an interactive console System.console(). Some info here. Commented Apr 16, 2018 at 23:20
  • 1
    See also this question. Commented Apr 16, 2018 at 23:26

1 Answer 1

2

Try (echo "user"; sleep 1; echo "password") | java javaprogram /home/user/securityfile

If that works you can refactor to read from file without too much work. If it doesn't, may be that app will never read from System.in since it requires an interactive console System.console(). Some info here.

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

1 Comment

You were spot on, I was doomed from the beginning. System.console() is what it is using. Thanks for the help.

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.