sixolar
2
Q:

java runtime exec get output

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();
}
0
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();
}
0

New to Communities?

Join the community