public class CommandExecutor extends BaseHostExecutor<com.jcraft.jsch.ChannelExec> implements ICommandExecutor
callback, channel, done, inputStream, outputStream, streamHandler| Constructor and Description |
|---|
CommandExecutor(com.jcraft.jsch.ChannelExec channel,
byte[] command) |
CommandExecutor(com.jcraft.jsch.ChannelExec channel,
String command) |
CommandExecutor(com.jcraft.jsch.ChannelExec channel,
String command,
String charset) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkTimeout()
检测是否超时
|
void |
close()
安全关闭
|
void |
env(byte[] key,
byte[] value)
设置环境变量
这里只支持设置 /etc/ssh/sshd_config AcceptEnv 的环境变量
否则只能使用 export LANG="en_US"; 来设置
|
void |
env(String key,
String value)
设置环境变量
这里只支持设置 /etc/ssh/sshd_config AcceptEnv 的环境变量
否则只能使用 export LANG="en_US"; 来设置
|
void |
errorStreamHandler(Consumer<InputStream> errorStreamHandler)
设置错误输出流处理器
|
void |
exec()
执行
|
String |
getCommand()
获取执行的命令
|
byte[] |
getCommandBytes()
获取执行的命令 byte
|
InputStream |
getErrorStream()
获取错误输出流
|
int |
getExitCode()
获取退出码
|
boolean |
isTimeout()
是否超时
|
protected void |
listenerOutput()
监听 标准输出/错误输出
|
void |
merge()
合并标准输出流和错误输出流
|
void |
pty(boolean enable)
是否使用伪终端
如果使用 当程序关闭时 命令进程一起关闭
如果不使用 当程序关闭时 命令进程可能不会一起关闭
必须在
HostConnector.connect()
之前调用 |
void |
setAgentForwarding(boolean enable)
启用代理转发
|
void |
timeout(long timeout,
TimeoutChecker<TimeoutEndpoint> checker)
设置超时时间
|
String |
toString() |
void |
transferError(OutputStream out)
传输错误输出流到指定输出流
|
void |
x11Forward(boolean enable)
是否启用 x11forwarding
|
callback, getChannel, getInputStream, getOutputStream, isDone, sendSignal, streamHandler, transfer, writeclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisSuccessExit, timeoutcallback, exit, exit, getInputStream, getOutputStream, interrupt, isDone, run, sendSignal, streamHandler, transfer, write, write, write, writeLine, writeLineconnect, connect, disconnect, disconnectChannel, disconnectSession, getChannel, getSession, isClosed, isConnected, isEofisDonepublic CommandExecutor(com.jcraft.jsch.ChannelExec channel,
String command)
public CommandExecutor(com.jcraft.jsch.ChannelExec channel,
String command,
String charset)
public CommandExecutor(com.jcraft.jsch.ChannelExec channel,
byte[] command)
public void pty(boolean enable)
ICommandExecutor如果使用 当程序关闭时 命令进程一起关闭 如果不使用 当程序关闭时 命令进程可能不会一起关闭
必须在
HostConnector.connect()
之前调用
pty in interface ICommandExecutorenable - 是否使用public void env(byte[] key,
byte[] value)
IHostExecutorenv in interface IHostExecutorkey - keyvalue - valuepublic void env(String key, String value)
IHostExecutorenv in interface IHostExecutorkey - keyvalue - valuepublic void x11Forward(boolean enable)
IHostExecutorx11Forward in interface IHostExecutorenable - 是否启用public void setAgentForwarding(boolean enable)
IHostExecutorsetAgentForwarding in interface IHostExecutorenable - 是否启用public void merge()
ICommandExecutormerge in interface ICommandExecutorpublic void errorStreamHandler(Consumer<InputStream> errorStreamHandler)
ICommandExecutorerrorStreamHandler in interface ICommandExecutorerrorStreamHandler - 错误输出流处理器public void transferError(OutputStream out) throws IOException
ICommandExecutortransferError in interface ICommandExecutorout - outIOException - IOExceptionpublic void timeout(long timeout,
TimeoutChecker<TimeoutEndpoint> checker)
ICommandExecutortimeout in interface ICommandExecutortimeout - timeoutchecker - checkerpublic boolean checkTimeout()
TimeoutEndpointcheckTimeout in interface TimeoutEndpointprotected void listenerOutput()
BaseHostExecutorlistenerOutput in class BaseHostExecutor<com.jcraft.jsch.ChannelExec>public void exec()
Executableexec in interface Executablepublic void close()
SafeCloseableclose in interface SafeCloseableclose in interface Closeableclose in interface AutoCloseableclose in class BaseHostExecutor<com.jcraft.jsch.ChannelExec>public int getExitCode()
ICommandExecutorgetExitCode in interface ICommandExecutorpublic String getCommand()
ICommandExecutorgetCommand in interface ICommandExecutorpublic byte[] getCommandBytes()
ICommandExecutorgetCommandBytes in interface ICommandExecutorpublic boolean isTimeout()
ICommandExecutorisTimeout in interface ICommandExecutorpublic InputStream getErrorStream()
ICommandExecutorgetErrorStream in interface ICommandExecutorCopyright © 2025. All rights reserved.