I create a bash script to read the output from another command (java -jar ...
).
The result from the command is like below:
MIN,MAX
6165350,6228865
I omit the first line using head -2 | tail -1
so the output will become
6165350,6228865
And i save it to the variable called output
output=$(java -jar bundletool.jar get-size total --apks=$APKS_PATH | head -2 | tail -1)
Last, I create java file to split the output results
import java.util.*;
public class Demo {
public static void main(String[] args) {
String[] values = args[0].split(",");
System.out.println(Integer.parseInt(values[0]));
System.out.println(Integer.parseInt(values[1]));
}
}
And below is the final bash script
#!bin/bash
output=$(java -jar bundletool.jar get-size total --apks=$APKS_PATH | head -2 | tail -1)
java Demo $output
When i run the bash, why i'm getting the error
6165350
"xception in thread "main" java.lang.NumberFormatException: For input string: "6228865
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.base/java.lang.Integer.parseInt(Integer.java:652)
at java.base/java.lang.Integer.parseInt(Integer.java:770)
at Demo.main(Demo.java:8)
I get the correct results when i try to change the output
output="6165350,6228865"
Thank you