fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7.  
  8. private static String output(InputStream inputStream) throws IOException {
  9. StringBuilder sb = new StringBuilder();
  10. BufferedReader br = null;
  11. try {
  12. br = new BufferedReader(new InputStreamReader(inputStream));
  13. String line = null;
  14. while ((line = br.readLine()) != null) {
  15. sb.append(line + System.getProperty("line.separator"));
  16. }
  17. } finally {
  18. br.close();
  19. }
  20. return sb.toString();
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. ProcessBuilder builder = new ProcessBuilder("ls", "-l");
  26.  
  27. try {
  28. Process p = builder.start();
  29. System.out.println("Output from 'ls -l':\n" + output(p.getInputStream()));
  30.  
  31. } catch (IOException e) {
  32. System.out.println("There's a problem.");
  33. }
  34.  
  35. }
  36. }
Success #stdin #stdout 0.24s 320960KB
stdin
Standard input is empty
stdout
Output from 'ls -l':
total 4
-rw-r--r-- 1 0 0 2018 Dec 16 02:59 tested.zip