Check out example codes for "java runtime exec get output". It will help you in understanding the concepts better.

Code Example 1

private static void GetOutput(final Process process) {
    new Thread() {
        public void run() {
            BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null; 
            try {
                while ((line = input.readLine()) != null) {
                    System.out.println(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
}

Code Example 2

private static void execCommand() {
  String[] command = {"echo", "Hello", "world."};
  
  new Thread(() -> {
    try {
      ProcessBuilder builder = new ProcessBuilder(command);
      builder.redirectErrorStream(true);
      final Process proc = builder.start();
      BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
      String s = null;
      while ((s = in.readLine()) != null) {
        System.out.println(s);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }).start();
}

Learn ReactJs, React Native from akashmittal.com