@Override public void run() { try { socket.write(command.toString() + "\n"); String reply = socket.readline(); socket.setPacketMode(true); if (reply == null) { ncException = new NovacomException("No data to read from socket"); } else if (reply.startsWith("ok")) { if (stdinRedirect != null) { writeFileToOutputStream(stdinRedirect); socket.closeInputOutput(); try { exitCode = socket.getExitCode(); } catch (Exception e1) { } } else if (stdoutRedirect != null) { writeInputStreamToFile(stdoutRedirect); socket.closeInputOutput(); try { exitCode = socket.getExitCode(); } catch (Exception e2) { } } else { response = collectResponse(); try { exitCode = socket.getExitCode(); } catch (NovacomException ne) { ncException = ne; } } } else { ncException = new NovacomException(reply); } } catch (IOException e) { System.err.println(e.getMessage()); ioException = e; exitCode = -1; } }
public int waitFor() throws InterruptedException, IOException, NovacomException { join(); socket.flush(); if (stdinRedirect == null && stdoutRedirect == null) { socket.closeInputOutput(); } socket.close(); if (ioException != null) { throw ioException; } if (ncException != null) { throw ncException; } return exitCode; }