code: public static StringBuffer runCommand(String[] cmd) {
      StringBuffer retval = new StringBuffer(MAX_OUTPUT_LENGTH);
      Process p;
      try {
        p = Runtime.getRuntime().exec(cmd);
        InputStream tmp = p.getInputStream();
        p.waitFor();
        int c;
        while ((c = tmp.read()) != -1)
          retval.append((char) c);
      } catch (IOException e) {
        e.printStackTrace();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
  
      return retval;
    }
docs: Runs a shell command in the system and provides a StringBuffer
  with the output of the command.
  
  @param cmd an array of string that form the command to run
  
  @return a StringBuffer that contains the output of the command