final String obfuscatedCmd = origCmd.toCommandLine(os, true);
logger.info("Starting command [{}] on [{}]", obfuscatedCmd, this);
try {
if (openShellBeforeExecute) {
Session session = null;
try {
logger.debug("Creating a temporary shell to allow for deferred home dir creation.");
session = getSshClient().startSession();
Session.Shell shell = session.startShell();
shell.close();
} finally {
closeQuietly(session);
}
}
Session session = getSshClient().startSession();
if (allocatePty != null && !allocatePty.isEmpty()) {
if (allocateDefaultPty) {
logger.warn("The " + ALLOCATE_PTY + " and " + ALLOCATE_DEFAULT_PTY
+ " connection options have both been set for the connection {}. Ignoring "
+ ALLOCATE_DEFAULT_PTY + " and using " + ALLOCATE_PTY + ".", this);
}
Matcher matcher = ptyPattern.matcher(allocatePty);
checkArgument(matcher.matches(), "Value for allocatePty [%s] does not match pattern \"" + PTY_PATTERN + "\"", allocateDefaultPty);
String term = matcher.group(1);
int cols = Integer.valueOf(matcher.group(2));
int rows = Integer.valueOf(matcher.group(3));
int width = Integer.valueOf(matcher.group(4));
int height = Integer.valueOf(matcher.group(5));
logger.debug("Allocating PTY {}:{}:{}:{}:{}", new Object[]{term, cols, rows, width, height});
session.allocatePTY(term, cols, rows, width, height, Collections.<PTYMode, Integer>emptyMap());
} else if (allocateDefaultPty) {
logger.debug("Allocating default PTY");
session.allocateDefaultPTY();
}
return createProcess(session, cmd);
} catch (SSHException e) {
throw new RuntimeIOException(format("Cannot start command [%s] on [%s]", obfuscatedCmd, this), e);
}