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. String domain = "google.com";
  13. String command = "/bin/bash -c 'echo -ne \"\\e[40m\\e[32m\"; ping -c1 " + domain + "; echo -ne \"\\e[0m\"'";
  14. try {
  15. Runtime rt = Runtime.getRuntime();
  16.  
  17. System.out.println("Executing command: `" + command + "`");
  18. Process proc = rt.exec(command);
  19.  
  20. BufferedReader stdInput = new BufferedReader(new
  21. InputStreamReader(proc.getInputStream()));
  22.  
  23. BufferedReader stdError = new BufferedReader(new
  24. InputStreamReader(proc.getErrorStream()));
  25.  
  26. // read the output from the command
  27. System.out.println("Standard output of the command:");
  28. String s = null;
  29. while ((s = stdInput.readLine()) != null) {
  30. System.out.println(s);
  31. }
  32.  
  33. // read any errors from the attempted command
  34. System.out.println("Standard error of the command:");
  35. while ((s = stdError.readLine()) != null) {
  36. System.out.println(s);
  37. }
  38.  
  39. int exitVal = proc.waitFor();
  40. System.out.println("Command exit value is: " + exitVal);
  41. } catch (Throwable t) {
  42. t.printStackTrace();
  43. }
  44. }
  45.  
  46. }
Success #stdin #stdout 0.08s 711680KB
stdin
Standard input is empty
stdout
Executing command: `/bin/bash -c 'echo -ne "\e[40m\e[32m"; ping -c1 google.com; echo -ne "\e[0m"'`
Standard output of the command:
Standard error of the command:
-ne: -c: line 0: unexpected EOF while looking for matching `''
-ne: -c: line 1: syntax error: unexpected end of file
Command exit value is: 2