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, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isSuccessExit, timeout
callback, exit, exit, getInputStream, getOutputStream, interrupt, isDone, run, sendSignal, streamHandler, transfer, write, write, write, writeLine, writeLine
connect, connect, disconnect, disconnectChannel, disconnectSession, getChannel, getSession, isClosed, isConnected, isEof
isDone
public 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 ICommandExecutor
enable
- 是否使用public void env(byte[] key, byte[] value)
IHostExecutor
env
in interface IHostExecutor
key
- keyvalue
- valuepublic void env(String key, String value)
IHostExecutor
env
in interface IHostExecutor
key
- keyvalue
- valuepublic void x11Forward(boolean enable)
IHostExecutor
x11Forward
in interface IHostExecutor
enable
- 是否启用public void setAgentForwarding(boolean enable)
IHostExecutor
setAgentForwarding
in interface IHostExecutor
enable
- 是否启用public void merge()
ICommandExecutor
merge
in interface ICommandExecutor
public void errorStreamHandler(Consumer<InputStream> errorStreamHandler)
ICommandExecutor
errorStreamHandler
in interface ICommandExecutor
errorStreamHandler
- 错误输出流处理器public void transferError(OutputStream out) throws IOException
ICommandExecutor
transferError
in interface ICommandExecutor
out
- outIOException
- IOExceptionpublic void timeout(long timeout, TimeoutChecker<TimeoutEndpoint> checker)
ICommandExecutor
timeout
in interface ICommandExecutor
timeout
- timeoutchecker
- checkerpublic boolean checkTimeout()
TimeoutEndpoint
checkTimeout
in interface TimeoutEndpoint
protected void listenerOutput()
BaseHostExecutor
listenerOutput
in class BaseHostExecutor<com.jcraft.jsch.ChannelExec>
public void exec()
Executable
exec
in interface Executable
public void close()
SafeCloseable
close
in interface SafeCloseable
close
in interface Closeable
close
in interface AutoCloseable
close
in class BaseHostExecutor<com.jcraft.jsch.ChannelExec>
public int getExitCode()
ICommandExecutor
getExitCode
in interface ICommandExecutor
public String getCommand()
ICommandExecutor
getCommand
in interface ICommandExecutor
public byte[] getCommandBytes()
ICommandExecutor
getCommandBytes
in interface ICommandExecutor
public boolean isTimeout()
ICommandExecutor
isTimeout
in interface ICommandExecutor
public InputStream getErrorStream()
ICommandExecutor
getErrorStream
in interface ICommandExecutor
Copyright © 2024. All rights reserved.