r2245 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh
Author: chatellier Date: 2009-05-19 07:48:17 +0000 (Tue, 19 May 2009) New Revision: 2245 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/SSHUtils.java Log: Add out args to get exec channel output Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/SSHUtils.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/SSHUtils.java 2009-05-18 17:17:14 UTC (rev 2244) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/SSHUtils.java 2009-05-19 07:48:17 UTC (rev 2245) @@ -28,11 +28,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.io.Writer; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.codelutin.util.MD5InputStream; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelExec; @@ -78,7 +77,21 @@ * @return channel exit status (0 = no problem) * @throws SSHException */ - public static int exec(Session session, String command) + public static int exec(Session session, String command) throws SSHException { + return exec(session, command, null); + } + + /** + * Exec command on remote server. + * + * @param session opened valid session + * @param command command to exec + * @param out exec output (can be null) + * + * @return channel exit status (0 = no problem) + * @throws SSHException + */ + public static int exec(Session session, String command, Writer out) throws SSHException { int exitStatus = 0; @@ -94,7 +107,10 @@ String line = null; while (true) { while ((line = br.readLine()) != null) { - if (log.isInfoEnabled()) { + if (out != null) { + out.write(line); + } + else if (log.isInfoEnabled()) { log.info("Remote output : " + line); } }
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org