Posted By

macbeth76 on 06/18/09


Tagged

process


Versions (?)

Java Tips - From Runtime.exec() to ProcessBuilder


 / Published in: Java
 

URL: http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html

  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class DoProcessBuilder {
  5. public static void main(String args[]) throws IOException {
  6.  
  7. if (args.length <= 0) {
  8. System.err.println("Need command to run");
  9. System.exit(-1);
  10. }
  11.  
  12. Process process = new ProcessBuilder(args).start();
  13. InputStream is = process.getInputStream();
  14. String line;
  15.  
  16. System.out.printf("Output of running %s is:",
  17. Arrays.toString(args));
  18.  
  19. while ((line = br.readLine()) != null) {
  20. System.out.println(line);
  21. }
  22.  
  23. }
  24. }

Report this snippet  

You need to login to post a comment.