Use of ProcessBuilder that duplicates the functions of the DoRuntime example: : ProcessBuilder « Development Class « Java






Use of ProcessBuilder that duplicates the functions of the DoRuntime example:

    
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
  public static void main(String args[]) throws IOException {

    Process process = new ProcessBuilder(args).start();
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;

    System.out.printf("Output of running %s is:", Arrays.toString(args));

    while ((line = br.readLine()) != null) {
      System.out.println(line);
    }

  }
}

   
    
    
    
  








Related examples in the same category

1.ProcessBuilder Demo
2.Use ProcessBuilder.environment()
3.Exec Helper
4.Launches a process, redirecting the output of that sub-process to the output of this (the parent) process.
5.Process Watcher
6.Execute a command