Shell

interface Shell

命令执行器接口。 该接口定义了与 shell 交互的基本操作,包括获取进程 ID、添加和移除监听器、执行命令等。

Author

M8Test, [email protected], https://m8test.com

Functions

Link copied to clipboard
abstract fun addOnCommandResultListener(listener: (Result) -> Unit): Boolean

添加命令执行结果监听器。 当命令执行完成时,会通知所有注册的监听器。

Link copied to clipboard
abstract fun addOnStderrLineListener(listener: (String) -> Unit): Boolean

添加标准错误输出行监听器。 当从标准错误输出读取一行数据时,会通知所有注册的监听器。

Link copied to clipboard
abstract fun addOnStdoutLineListener(listener: (String) -> Unit): Boolean

添加标准输出行监听器。 当从标准输出读取一行数据时,会通知所有注册的监听器。

Link copied to clipboard
abstract fun exec(command: String, configBuilder: Config.() -> Unit): Result

在当前 Shell 运行命令。 根据指定的命令和配置信息执行命令,并返回命令执行的结果。

Link copied to clipboard
abstract fun getPid(): Int

获取 Shell 进程 id。 该 ID 用于唯一标识当前 shell 进程。

Link copied to clipboard
abstract fun isAlive(): Boolean

检查当前 Shell 是否还存活并能够执行命令。 如果 Shell 存活,则可以继续执行命令;否则需要重新创建。

Link copied to clipboard
abstract fun isIdle(): Boolean

检查当前 Shell 是否处于空闲状态。 如果 Shell 处于空闲状态,则可以立即执行新的命令。

Link copied to clipboard
abstract fun isRunning(): Boolean

检查当前 Shell 是否正在运行命令。 如果 Shell 正在运行命令,则不能同时执行其他命令。

Link copied to clipboard
abstract fun isShutdown(): Boolean

检查当前 Shell 是否关闭。 如果 Shell 已经关闭,则无法再执行命令。

Link copied to clipboard
abstract fun removeOnCommandResultListener(listener: (Result) -> Unit): Boolean

移除命令执行结果监听器。 移除指定的监听器,使其不再接收命令执行结果的通知。

Link copied to clipboard
abstract fun removeOnStderrLineListener(listener: (String) -> Unit): Boolean

移除标准错误输出行监听器。 移除指定的监听器,使其不再接收标准错误输出行的通知。

Link copied to clipboard
abstract fun removeOnStdoutLineListener(listener: (String) -> Unit): Boolean

移除标准输出行监听器。 移除指定的监听器,使其不再接收标准输出行的通知。

Link copied to clipboard
abstract fun shutdown()

关闭当前 ShellShell 被关闭后将无法执行命令,并且应该被垃圾回收。