Normally I use this code to run a bash script and get it's output
ProcessBuilder pb = new ProcessBuilder("/home/myscript");
Process p = pb.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputRead;
p.waitFor();
while((inputRead=stdInput.readLine()) != null){
Helper.log(inputRead);
}
This works fine but this time the bash script I am using didn't terminate. It's always active and when it detect something it print it. I want to start the script, wait for some time and than check if it detected something. I tried to use p.wait(periode);
I tried this code
p.wait(10000);
while((inputRead=stdInput.readLine()) != null){
Helper.log(inputRead);
}
I am not sure if it's the right solution for my problem but anyway I get an error with this code
java.lang.IllegalMonitorStateException
My question is not really about waiting, but how to stop the process after waiting and still be able to get the output.