예제 #1
0
 @Override
 public ExecResponse create() throws Exception {
   try {
     session = acquire(execConnection());
     Command output = session.exec(checkNotNull(command, "command"));
     String outputString = IOUtils.readFully(output.getInputStream()).toString();
     output.join(timeoutMillis, TimeUnit.SECONDS);
     int errorStatus = output.getExitStatus();
     String errorString = IOUtils.readFully(output.getErrorStream()).toString();
     return new ExecResponse(outputString, errorString, errorStatus);
   } finally {
     clear();
   }
 }
예제 #2
0
파일: Exec.java 프로젝트: majinding/sshj
  public static void main(String... args) throws IOException {
    final SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();

    ssh.connect("localhost");
    try {
      ssh.authPublickey(System.getProperty("user.name"));
      final Session session = ssh.startSession();
      try {
        final Command cmd = session.exec("ping -c 1 google.com");
        System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
        cmd.join(5, TimeUnit.SECONDS);
        System.out.println("\n** exit status: " + cmd.getExitStatus());
      } finally {
        session.close();
      }
    } finally {
      ssh.disconnect();
    }
  }
예제 #3
0
 @Override
 protected void closeAllStreams() {
   IOUtils.closeQuietly(err);
   super.closeAllStreams();
 }
예제 #4
0
 private void finishOff() {
   reader.interrupt();
   IOUtils.closeQuietly(connInfo.in);
   IOUtils.closeQuietly(connInfo.out);
 }