Example #1
0
File: SSH.java Project: ning/atlas
  public String exec(String command, int time, TimeUnit unit) throws IOException {
    Session s = ssh.startSession();
    try {
      Session.Command cmd = s.exec(command);

      StringBuilder all = new StringBuilder();
      BufferedReader out = new BufferedReader(new InputStreamReader(cmd.getInputStream()));
      String buf;
      while (null != (buf = out.readLine())) {
        logger.debug(buf);
        all.append(buf).append("\n");
      }

      cmd.join(time, unit);
      cmd.close();
      return all.toString();
    } finally {
      s.close();
    }
  }