How to pass a string variable as a shell script argument?-Collection of common programming errors
You’ll want to call the command as follows:
Process process = new ProcessBuilder().command("sh", "/path/shell.sh", var1, var2);
Scanner scan = new Scanner(process.getInputStream());
while(scan.hasNextLine()) {
//...
}
//...
scan.close();
process.destroy();
You’ll probably want to wrap that in a try-catch
block too.