0

I have pretty simple wrapper script which aquires parameters and passes them to java jar. Unfortunatly, I experience very-very strange behaviour. Below is an example.

Command to execute script:

./wrapper http://localhost:8485/metrics 900 200

Script:

#/bin/sh

/usr/java/default/bin/java -jar /usr/plugins/checkmetrics.jar $@

Java code:

public static void main(String[] args) throws IOException {
    String metricsUrl = args[0];
    int heapWarnValue = Integer.parseInt(args[1]);
    int threadWarnValue = Integer.parseInt(args[2]);
}

Which gives me NumberFormatException:

"xception in thread "main" java.lang.NumberFormatException: For input string: "200

But if I change command to following, everything works:

./wrapper http://localhost:8485/metrics 900 200" "

Breaks my brain, but I can't understand where I'm wrong. Could someone explain? Thanks in advance

2
  • Can you try change your script to: /usr/java/default/bin/java -jar /usr/plugins/checkmetrics.jar "$@" Commented May 3, 2018 at 13:16
  • @AvihooMamka, I tried and got the same result. Commented May 3, 2018 at 13:35

1 Answer 1

3

Is there an LF or CR character at the end of the script that is not being correctly processed (could happen if you have unix line endings in a windows environment or vice versa)?

the reason I mention this is that the error you mention says that it is

For input string: "200

I'm willing to bet that there is another quote mark at the start of the next line. If that's the case, it's trying to parse 200 and CR together as an integer. Sort out the line endings and all will be fine.

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

1 Comment

Yes, you are totally right, "cat -e wrapper" shows that I have CRLF file endings (^M$). Change it to LF and everything works.

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.