}
}
private void runSshCommand(String... args) throws Exception {
SshConfig sshConfig = sshContext.buildConfig(new InetSocketAddress("127.0.0.1", 2222));
StringBuilder cmd = new StringBuilder();
for (String arg : args) {
if (cmd.length() != 0) {
cmd.append(' ');
}
// TODO: Check for spaces and quote??
cmd.append(arg);
}
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
int exitCode = sshConfig.execute(cmd.toString(), stdout, stderr);
if (exitCode != 0) {
System.out.println("Command: " + cmd);
System.out.println("STDOUT: " + new String(stdout.toByteArray(), Charsets.UTF_8));
System.out.println("STDERR: " + new String(stderr.toByteArray(), Charsets.UTF_8));