// all errors will be captured in the error stream
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
ChannelExec channel = null;
try {
Session session = createSSHSession(host);
channel = (ChannelExec) session.openChannel("exec");
channel.setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(errorStream);
InputStream in=channel.getInputStream();
// connect actually execs the process on a remote node