public class PtyCapableChannelSession extends ChannelSession
Serves as the base channel session for executing remote commands - including
a full shell. Note: all the configuration changes via the various
setXXX methods must be made before the channel is actually
open. If they are invoked afterwards then they have no effect (silently
ignored).
A typical code snippet would be:
try(client = SshClient.setUpDefaultClient()) {
client.start();
try(ClientSession s = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) {
s.addPasswordIdentity(getCurrentTestName());
s.auth().verify(5L, TimeUnit.SECONDS);
try(ChannelExec shell = s.createExecChannel("my super duper command")) {
shell.setEnv("var1", "val1");
shell.setEnv("var2", "val2");
...etc...
shell.setPtyType(...);
shell.setPtyLines(...);
...etc...
shell.open().verify(5L, TimeUnit.SECONDS);
shell.waitFor(ClientChannel.CLOSED, TimeUnit.SECONDS.toMillis(17L)); // can use zero for infinite wait
Integer status = shell.getExitStatus();
if (status.intValue() != 0) {
...error...
}
}
} finally {
client.stop();
}
}
AbstractChannel.GracefulChannelCloseable, AbstractChannel.GracefulStateCloseableUtils.AbstractCloseable.StateClientChannel.Streaming| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_COLUMNS_COUNT |
static int |
DEFAULT_HEIGHT |
static Map<PtyMode,Integer> |
DEFAULT_PTY_MODES |
static int |
DEFAULT_ROWS_COUNT |
static int |
DEFAULT_WIDTH |
asyncErr, asyncIn, asyncOut, err, exitSignal, exitStatus, in, invertedErr, invertedIn, invertedOut, opened, openFailureMsg, openFailureReason, openFuture, out, streaming, typeDEFAULT_CHANNEL_CLOSE_TIMEOUT, DEFAULT_PACKET_SIZE, DEFAULT_WINDOW_SIZE, eof, executor, gracefulFuture, gracefulState, handlers, id, localWindow, recipient, remoteWindow, RESPONSE_BUFFER_GROWTH_FACTOR, service, session, shutdownExecutorcloseFuture, lock, statelogCHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM, CLOSED, EOF, EXIT_SIGNAL, EXIT_STATUS, OPENED, STDERR_DATA, STDOUT_DATA, TIMEOUT| Constructor and Description |
|---|
PtyCapableChannelSession(boolean usePty) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doOpenPty() |
int |
getPtyColumns() |
int |
getPtyHeight() |
int |
getPtyLines() |
Map<PtyMode,Integer> |
getPtyModes() |
String |
getPtyType() |
int |
getPtyWidth() |
boolean |
isAgentForwarding() |
boolean |
isUsePty() |
void |
sendWindowChange(int columns,
int lines,
int height,
int width) |
void |
setAgentForwarding(boolean agentForwarding) |
void |
setEnv(String key,
String value) |
void |
setPtyColumns(int ptyColumns) |
void |
setPtyHeight(int ptyHeight) |
void |
setPtyLines(int ptyLines) |
void |
setPtyModes(Map<PtyMode,Integer> ptyModes) |
void |
setPtyType(String ptyType) |
void |
setPtyWidth(int ptyWidth) |
void |
setupSensibleDefaultPty() |
void |
setUsePty(boolean usePty) |
doCloseImmediately, doOpen, pumpInputStream, securedReaddoWriteData, doWriteExtendedData, getAsyncErr, getAsyncIn, getAsyncOut, getErr, getExitStatus, getIn, getInnerCloseable, getInvertedErr, getInvertedIn, getInvertedOut, getOut, getStreaming, handleOpenFailure, handleOpenSuccess, handleWindowAdjust, open, open, setErr, setIn, setOut, setStreaming, waitForaddRequestHandler, configureWindow, getExecutorService, getId, getLocalWindow, getRecipient, getRemoteWindow, getSession, handleClose, handleData, handleEof, handleExtendedData, handleFailure, handleRequest, init, isEofSignalled, isShutdownOnExit, notifyStateChanged, sendEof, sendResponse, sendWindowAdjust, setEofSignalled, setExecutorService, setShutdownOnExit, toString, writePacketdoCloseGracefullybuilder, close, isClosed, isClosing, preCloseclose, isOpenclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitclosepublic static final int DEFAULT_COLUMNS_COUNT
public static final int DEFAULT_ROWS_COUNT
public static final int DEFAULT_WIDTH
public static final int DEFAULT_HEIGHT
public void setupSensibleDefaultPty()
public boolean isAgentForwarding()
public void setAgentForwarding(boolean agentForwarding)
public boolean isUsePty()
public void setUsePty(boolean usePty)
public String getPtyType()
public void setPtyType(String ptyType)
public int getPtyColumns()
public void setPtyColumns(int ptyColumns)
public int getPtyLines()
public void setPtyLines(int ptyLines)
public int getPtyWidth()
public void setPtyWidth(int ptyWidth)
public int getPtyHeight()
public void setPtyHeight(int ptyHeight)
public void sendWindowChange(int columns,
int lines,
int height,
int width)
throws IOException
IOExceptionprotected void doOpenPty()
throws IOException
IOExceptionCopyright © 2008–2015 The Apache Software Foundation. All rights reserved.