Since the process will run in a new thread, there is probably no way out or incomplete output available when you go to your while loop.
Process p = pb.start(); // process runs in another thread parallel to this one BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream())); // bri may be empty or incomplete. while ((line = bri.readLine()) != null) { RESULT+=line; }
Therefore, you need to wait for the process to complete before trying to interact with it. Try using the Process.waitFor () method to pause the current thread until your process can complete.
Process p = pb.start(); p.waitFor(); // wait for process to finish then continue. BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = bri.readLine()) != null) { RESULT+=line; }
This is a simple approach that you can also process the output of a process during its parallel operation, but then you will need to control the state of the process, that is, it is still running or completed, and the availability of output.
jsuhre
source share