0

trying to pass line info (2 lines reprensting a user and a password) to a java application, the log show that it take the lines but empty value (like only tkae the \n

code is decompiled (only have the copiled version) showing this function and call

public String getUser(String prompt)
  {
    System.out.print(prompt);

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String userName = null;

    try
    {
      return br.readLine();
    }
    catch (IOException ioe) {
      System.out.println("IO error trying to read your name!"); }
    return null;
  }

call in main code is

 try
      {
        String user = application.getUser("User: ");
        User = user;
        char[] pswd = application.getPassword(System.in, "Password: ");
        if (application.isDebug()) {
          application.log("verify User " + User);
          }
        ...
      }
  else {
          application.log("ID not found!");
        }
  }
  catch (Exception e) {
    application.log("Exception during login, abort Batch now!");
    System.exit(1);
  }

calling with different redirection from the shell ex:

printf "%s\n%s\n" "MyUser" "MyPwd" | java SomeArguement  Compiledjar

show this in log

User: Password: [2019-09-25 14:06:26 CEST] getUserPlatformContext [2019-09-25 14:06:26 CEST] Exception during login, abort Batch now!

any idea why STDIN in not "read" correctly by this code (this other post confirm it should).

I also put lot more string to pass in case of previous code read STDIN before but it's the same

----------- Other story ----------------------- finaly found the debug argument to pass and it show that the STDIN is correctly read for the user prompt but hang on the getpassword that use a buffer read from another type like ((PushbackInputStream)in).unread(c2) and failed at this level.

user207421
  • 305,947
  • 44
  • 307
  • 483
NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43
  • You'll probably find it helpful to actually print out what the exception is in your error message. – Shawn Sep 25 '19 at 13:44
  • Log the exception too, message and best stacktrace (where which exception was thrown). – Joop Eggen Sep 25 '19 at 13:44
  • @Shawn no idea of the exception, only have the log on STDERR. User = user; because it is used under the second shape later (i'm not the owner of the code and can't change it). My problem is to feed the java – NeronLeVelu Sep 25 '19 at 14:15
  • Have you tried to just run `java SomeArguement Compiledjar` and then wait for prompts and input values? I think issue is not in java code but in that piped linux command – Ivan Sep 25 '19 at 14:31
  • @ivan/ in this direct access, the appli prompt for user than password and go like it should. problem is indeed from the shell STDIN redirection that the application don't catch like i imagine it should. OS is AIX in my case. – NeronLeVelu Sep 25 '19 at 14:35
  • @user207421 this what i suspected but how can i send the input in this case. I don't have any possibilities to modify the java application. How can i feed 2 stream or at lest make the first close allowing the second to receive the following lines ? using a special sequence of char or something like a char 0 ? – NeronLeVelu Sep 26 '19 at 06:32
  • 1
    You can't. The code was misdesiged in such a way that the only possible input device is a console. – user207421 Sep 26 '19 at 10:38
  • 1
    Some kind person has deleted my comment identifying the actual problem here, which is that two `BufferedReaders` were used, the first of which swallowed all the input, which in turn caused the second one to be at end of stream, which in turn caused the `password` String to be null, which in turn caused a `NullPointerException`. It would be appreciated if this nuisance could cease forthwith. – user207421 Sep 27 '19 at 01:17

0 Answers0