fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println(runSystemCommand("ls", "-l", "."));
  13. }
  14. public static String runSystemCommand(String... command) {
  15. String s = "", v = "";
  16. try {
  17. ProcessBuilder builder = new ProcessBuilder(command);
  18. builder.redirectErrorStream(true);
  19.  
  20. Process p = builder.start();
  21. BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
  22.  
  23. while (true) {
  24. s = r.readLine();
  25. if (s == null) { break; }
  26. v += s;
  27. }
  28.  
  29. return v;
  30. } catch (Exception e) {
  31. return e.getMessage();
  32. }
  33.  
  34. }
  35. }
Success #stdin #stdout 0.16s 53500KB
stdin
Standard input is empty
stdout
total 4-rw-r--r-- 1 0 0 2245 Dec 16 14:43 tested.zip