Java Tips - From Runtime.exec() to ProcessBuilder


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your 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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.