1private static void execCommand() {
2 String[] command = {"echo", "Hello", "world."};
3
4 new Thread(() -> {
5 try {
6 ProcessBuilder builder = new ProcessBuilder(command);
7 builder.redirectErrorStream(true);
8 final Process proc = builder.start();
9 BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
10 String s = null;
11 while ((s = in.readLine()) != null) {
12 System.out.println(s);
13 }
14 } catch (IOException e) {
15 e.printStackTrace();
16 }
17 }).start();
18}
1private static void GetOutput(final Process process) {
2 new Thread() {
3 public void run() {
4 BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
5 String line = null;
6 try {
7 while ((line = input.readLine()) != null) {
8 System.out.println(line);
9 }
10 } catch (IOException e) {
11 e.printStackTrace();
12 }
13 }
14 }.start();
15}