List of usage examples for org.apache.commons.net.bsd RCommandClient rexec
public void rexec(String username, String password, String command, boolean separateErrorStream) throws IOException
From source file:org.squale.welcom.outils.rsh.Impl.JavaRshClient.java
/** * Retourne le resultat d'un commande Unix en rsh Attention : le buffer est limit a 1024. * /*from ww w.j a v a 2s . c o m*/ * @param cmd : Commande unix * @param buff : Ecrit dans l'entree standard le contenu * @throws IOException : Retourne le buffer rcp ou bien une erreur d'execution * @return resultat unix */ public int executecmd(final String cmd, final byte buff[]) throws IOException { lastReturnStream = null; lastErrorStream = null; final RCommandClient rsh = new RCommandClient(); // Stocke ce que l'on a envoyer addMessage(">" + cmd + "\n"); try { rsh.connect(serveur); rsh.rexec(loginLocal, loginDistant, cmd + "\n", true); // Si on a quelquechose dans le buffer if (buff != null) { CopyUtils.copy(buff, rsh.getOutputStream()); addMessage(buff); rsh.getOutputStream().close(); // Faut etre dconnecter avant de lire if ((rsh != null) && rsh.isConnected()) { rsh.disconnect(); } } if (rsh.getInputStream() != null) { lastReturnStream = IOUtils.toString(rsh.getInputStream()); addMessage(lastReturnStream); } if (rsh.getErrorStream() != null) { lastErrorStream = IOUtils.toString(rsh.getErrorStream()); if (lastErrorStream.length() > 0) { addMessage(lastErrorStream); return 1; } } } catch (final IOException ioe) { addMessage(ioe.getMessage()); throw ioe; } finally { if ((rsh != null) && rsh.isConnected()) { rsh.disconnect(); } } addMessage(">OK\n"); return 0; }