运行工具
public interface IRunUtil
com.android.tradefed.util.IRunUtil |
用于运行定时操作和系统命令的接口。
概括
嵌套类 | |
---|---|
interface | IRunUtil.IRunnableResult 用于异步执行返回布尔状态的操作的接口。 |
公共方法 | |
---|---|
abstract void | allowInterrupt (boolean allow) 允许/禁止当前线程上的运行中断。 |
abstract void | interrupt (Thread thread, String message, ErrorIdentifier errorId) 中断给定线程上正在进行/即将进行的运行操作。 |
abstract void | interrupt (Thread thread, String message) 中断给定线程上正在进行/即将进行的运行操作。 |
abstract boolean | isInterruptAllowed () 给出 RunUtil 的中断状态。 |
abstract Process | runCmdInBackground (Redirect redirect, command) runCmdInBackground (Redirect redirect, command) 另一个 |
abstract Process | runCmdInBackground ( command) runCmdInBackground ( command) 另一个 |
abstract Process | runCmdInBackground ( command, OutputStream output) runCmdInBackground ( command, OutputStream output) 运行带有 |
abstract Process | runCmdInBackground (String... command) 异步执行系统命令的辅助方法。 |
abstract Process | runCmdInBackground (Redirect redirect, String... command) 异步执行系统命令的辅助方法。 |
abstract boolean | runEscalatingTimedRetry (long opTimeout, long initialPollInterval, long maxPollInterval, long maxTime, IRunUtil.IRunnableResult runnable) 多次阻塞并执行一个操作,直到成功。 |
abstract boolean | runFixedTimedRetry (long opTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable) 多次阻塞并执行一个操作,直到成功。 |
abstract CommandStatus | runTimed (long timeout, IRunUtil.IRunnableResult runnable, boolean logErrors) 阻止并执行操作,如果花费的时间超过指定时间则中止。 |
abstract CommandResult | runTimedCmd (long timeout, OutputStream stdout, OutputStream stderr, String... command) 用于执行系统命令的帮助程序方法,如果花费的时间超过指定时间则中止,并将输出重定向到文件(如果指定)。 |
abstract CommandResult | runTimedCmd (long timeout, String... command) 执行系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。 |
abstract CommandResult | runTimedCmdRetry (long timeout, long retryInterval, int attempts, String... command) 执行系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。 |
abstract CommandResult | runTimedCmdSilently (long timeout, String... command) 执行系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。 |
abstract CommandResult | runTimedCmdSilentlyRetry (long timeout, long retryInterval, int attempts, String... command) 执行系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。 |
abstract CommandResult | runTimedCmdWithInput (long timeout, String input, File stdoutFile, File stderrFile, String... command) 用于执行系统命令的帮助程序方法,如果花费的时间超过指定时间则中止,并将输出重定向到文件(如果指定)。 |
abstract CommandResult | runTimedCmdWithInput (long timeout, String input, String... command) 用于执行需要 stdin 输入的系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。 |
abstract CommandResult | runTimedCmdWithInput (long timeout, String input, command) runTimedCmdWithInput (long timeout, String input, command) 用于执行需要 stdin 输入的系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。 |
abstract CommandResult | runTimedCmdWithInputRedirect (long timeout, File inputRedirect, String... command) 用于执行需要从文件重定向 Stdin 的系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。 |
abstract boolean | runTimedRetry (long opTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable) 多次阻塞并执行一个操作,直到成功。 |
abstract void | setEnvVariable (String key, String value) 设置运行系统命令时要使用的环境变量。 |
abstract void | setEnvVariablePriority ( IRunUtil.EnvPriority priority) 决定在创建进程时是否取消设置环境变量的优先级高于设置它们。 |
abstract void | setInterruptibleInFuture (Thread thread, long timeMs) 等待一段时间后设置为可中断。 |
abstract void | setLinuxInterruptProcess (boolean interrupt) 允许在超时时对通过 #runTimed 方法运行的进程使用 linux“kill”中断。 |
abstract void | setRedirectStderrToStdout (boolean redirect) 设置标准错误流以在运行系统命令时重定向到标准输出流。 |
abstract void | setWorkingDir (File dir) 设置系统命令的工作目录。 |
abstract void | sleep (long time) 帮助程序方法在给定时间内休眠,忽略任何异常。 |
abstract void | unsetEnvVariable (String key) 取消设置环境变量,因此系统命令在没有此环境变量的情况下运行。 |
公共方法
允许中断
public abstract void allowInterrupt (boolean allow)
允许/禁止当前线程上的运行中断。如果允许,可以通过interrupt(Thread, String)
方法从其他线程中断当前线程的运行操作。
参数 | |
---|---|
allow | boolean : 是否允许当前线程运行中断。 |
打断
public abstract void interrupt (Thread thread, String message, ErrorIdentifier errorId)
中断给定线程上正在进行/即将进行的运行操作。给定线程上的运行操作将抛出RunInterruptedException
。
参数 | |
---|---|
message | String : RunInterruptedException 的消息。 |
errorId | ErrorIdentifier :表示已知的中断原因。 |
打断
public abstract void interrupt (Thread thread, String message)
中断给定线程上正在进行/即将进行的运行操作。给定线程上的运行操作将抛出RunInterruptedException
。
参数 | |
---|---|
message | String : RunInterruptedException 的消息。 |
允许中断
public abstract boolean isInterruptAllowed ()
给出 RunUtil 的中断状态。
退货 | |
---|---|
boolean | 如果运行可以中断,则为 true,否则为 false。 |
运行CmdInBackground
public abstract Process runCmdInBackground (Redirect redirect,command)
另一个runCmdInBackground(String)
方法,它接受ERROR(/List)
形式的命令参数。
参数 | |
---|---|
redirect | Redirect :应用于ProcessBuilder ERROR(/Redirect) 。 |
command | ERROR(/List) 包含指定的系统命令和可选的 exec 参数 |
退货 | |
---|---|
Process | 执行命令的Process |
投掷 | |
---|---|
| 如果命令运行失败 |
运行CmdInBackground
public abstract Process runCmdInBackground (command)
另一个runCmdInBackground(String)
方法,它接受ERROR(/List)
形式的命令参数。
参数 | |
---|---|
command | ERROR(/List) 包含指定的系统命令和可选的 exec 参数 |
退货 | |
---|---|
Process | 执行命令的Process |
投掷 | |
---|---|
| 如果命令运行失败 |
运行CmdInBackground
public abstract Process runCmdInBackground (command, OutputStream output)
运行带有ERROR(/OutputStream)
的命令会记录命令的输出。 Stdout 和 stderr 合并在一起。
参数 | |
---|---|
command | |
output | OutputStream :保存输出的OutputStream |
退货 | |
---|---|
Process | 运行命令的Process |
投掷 | |
---|---|
| IO异常 |
运行CmdInBackground
public abstract Process runCmdInBackground (String... command)
异步执行系统命令的辅助方法。
启动命令后立即返回。
参数 | |
---|---|
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
Process | 执行命令的Process |
投掷 | |
---|---|
| 如果命令运行失败 |
运行CmdInBackground
public abstract Process runCmdInBackground (Redirect redirect, String... command)
异步执行系统命令的辅助方法。
启动命令后立即返回。
参数 | |
---|---|
redirect | Redirect :应用于ProcessBuilder ERROR(/Redirect) 。 |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
Process | 执行命令的Process |
投掷 | |
---|---|
| 如果命令运行失败 |
运行升级定时重试
public abstract boolean runEscalatingTimedRetry (long opTimeout, long initialPollInterval, long maxPollInterval, long maxTime, IRunUtil.IRunnableResult runnable)
多次阻塞并执行一个操作,直到成功。
操作尝试之间的等待时间呈指数增加。这是为了在执行轮询服务器等操作时使用,以便在服务器暂时关闭时为其提供恢复时间。参数 | |
---|---|
opTimeout | long :单次操作尝试等待的最长时间(以毫秒为单位) |
initialPollInterval | long :操作尝试之间等待的初始时间 |
maxPollInterval | long :操作尝试之间等待的最长时间 |
maxTime | long :继续尝试操作的总的近似最大时间 |
runnable | IRunUtil.IRunnableResult :要执行的IRunUtil.IRunnableResult |
退货 | |
---|---|
boolean | true 如果操作在 maxTime 过期之前成功完成 |
运行固定定时重试
public abstract boolean runFixedTimedRetry (long opTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable)
多次阻塞并执行一个操作,直到成功。
参数 | |
---|---|
opTimeout | long :单次操作尝试等待的最长时间(以毫秒为单位) |
pollInterval | long :操作尝试之间等待的初始时间 |
maxTime | long :继续尝试操作的总的近似最大时间 |
runnable | IRunUtil.IRunnableResult :要执行的IRunUtil.IRunnableResult |
退货 | |
---|---|
boolean | true 如果操作在 maxTime 过期之前成功完成 |
运行时
public abstract CommandStatus runTimed (long timeout, IRunUtil.IRunnableResult runnable, boolean logErrors)
阻止并执行操作,如果花费的时间超过指定时间则中止。
参数 | |
---|---|
timeout | long :等待的最长时间(以毫秒为单位) |
runnable | IRunUtil.IRunnableResult :要执行的IRunUtil.IRunnableResult |
logErrors | boolean :是否记录异常错误。 |
退货 | |
---|---|
CommandStatus | CommandStatus 操作结果。 |
运行定时命令
public abstract CommandResult runTimedCmd (long timeout, OutputStream stdout, OutputStream stderr, String... command)
用于执行系统命令的帮助程序方法,如果花费的时间超过指定时间则中止,并将输出重定向到文件(如果指定)。当以这种方式提供ERROR(/OutputStream)
时,它们将在函数末尾保持打开状态。
参数 | |
---|---|
timeout | long :超时等待的最长时间(以毫秒为单位)。 0 表示没有超时。 |
stdout | OutputStream : ERROR(/OutputStream) 其中 std 输出将被重定向。可以为空。 |
stderr | OutputStream : ERROR(/OutputStream) 错误输出将被重定向。可以为空。 |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
运行定时命令
public abstract CommandResult runTimedCmd (long timeout, String... command)
执行系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。
参数 | |
---|---|
timeout | long :等待的最长时间(以毫秒为单位)。 0 表示没有超时。 |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
运行定时命令重试
public abstract CommandResult runTimedCmdRetry (long timeout, long retryInterval, int attempts, String... command)
执行系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。
参数 | |
---|---|
timeout | long :每次尝试等待的最长时间(以毫秒为单位) |
retryInterval | long :命令重试之间等待的时间 |
attempts | int : 最大尝试次数 |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
静默运行定时命令
public abstract CommandResult runTimedCmdSilently (long timeout, String... command)
执行系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。与runTimedCmd(long, String)
类似,但不会记录任何异常错误。
参数 | |
---|---|
timeout | long :等待的最长时间(以毫秒为单位) |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
runTimedCmd静默重试
public abstract CommandResult runTimedCmdSilentlyRetry (long timeout, long retryInterval, int attempts, String... command)
执行系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。与runTimedCmdRetry(long, long, int, String[])
类似,但不会记录任何异常错误。
参数 | |
---|---|
timeout | long :等待的最长时间(以毫秒为单位) |
retryInterval | long :命令重试之间等待的时间 |
attempts | int : 最大尝试次数 |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
带输入的运行定时命令
public abstract CommandResult runTimedCmdWithInput (long timeout, String input, File stdoutFile, File stderrFile, String... command)
用于执行系统命令的帮助程序方法,如果花费的时间超过指定时间则中止,并将输出重定向到文件(如果指定)。
参数 | |
---|---|
timeout | long :超时等待的最长时间(以毫秒为单位)。 0 表示没有超时。 |
input | String :传递给进程的标准输入 |
stdoutFile | File : ERROR(/File) 其中标准输出将被重定向。可以为空。 |
stderrFile | File : ERROR(/File) ,错误输出将被重定向。可以为空。 |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
带输入的运行定时命令
public abstract CommandResult runTimedCmdWithInput (long timeout, String input, String... command)
用于执行需要 stdin 输入的系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。
参数 | |
---|---|
timeout | long :等待的最长时间(以毫秒为单位) |
input | String :传递给进程的标准输入 |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
带输入的运行定时命令
public abstract CommandResult runTimedCmdWithInput (long timeout, String input,command)
用于执行需要 stdin 输入的系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。
参数 | |
---|---|
timeout | long :等待的最长时间(以毫秒为单位) |
input | String :传递给进程的标准输入 |
command | ERROR(/List) 包含系统命令和可选的 exec 参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
runTimedCmdWithInputRedirect
public abstract CommandResult runTimedCmdWithInputRedirect (long timeout, File inputRedirect, String... command)
用于执行需要从文件重定向 Stdin 的系统命令的帮助程序方法,如果花费的时间超过指定时间,则中止。
参数 | |
---|---|
timeout | long :等待的最长时间(以毫秒为单位) |
inputRedirect | File :使用ProcessBuilder.redirectInput() 将ERROR(/File) 重定向为标准输入。如果为 null,则 stdin 将不会被重定向。 |
command | String : 指定的系统命令和 exec 的可选参数 |
退货 | |
---|---|
CommandResult | 包含命令运行结果的CommandResult |
运行定时重试
public abstract boolean runTimedRetry (long opTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)
多次阻塞并执行一个操作,直到成功。
参数 | |
---|---|
opTimeout | long :一次操作尝试等待的最长时间(以毫秒为单位) |
pollInterval | long :命令重试之间等待的时间 |
attempts | int : 最大尝试次数 |
runnable | IRunUtil.IRunnableResult :要执行的IRunUtil.IRunnableResult |
退货 | |
---|---|
boolean | 如果操作在尝试到达之前成功完成,则为true 。 |
设置环境变量
public abstract void setEnvVariable (String key, String value)
设置运行系统命令时要使用的环境变量。
参数 | |
---|---|
key | String :变量名 |
value | String :变量值 |
也可以看看:
设置环境变量优先级
public abstract void setEnvVariablePriority (IRunUtil.EnvPriority priority)
决定在创建进程时是否取消设置环境变量的优先级高于设置它们。默认情况下,取消设置具有更高的优先级:这意味着如果尝试设置具有相同名称的变量,则不会发生这种情况,因为该变量将被取消设置。不能在默认IRunUtil
实例上使用。
参数 | |
---|---|
priority | IRunUtil.EnvPriority |
设置可中断的未来
public abstract void setInterruptibleInFuture (Thread thread, long timeMs)
等待一段时间后设置为可中断。 ERROR(/CommandScheduler#shutdownHard())
强制我们最终终止。
参数 | |
---|---|
thread | Thread :将变得可中断的线程。 |
timeMs | long :设置可中断之前等待的时间。 |
设置Linux中断进程
public abstract void setLinuxInterruptProcess (boolean interrupt)
允许在超时时对通过 #runTimed 方法运行的进程使用 linux“kill”中断。不能在默认IRunUtil
实例上使用。
参数 | |
---|---|
interrupt | boolean |
setRedirectStderrToStdout
public abstract void setRedirectStderrToStdout (boolean redirect)
设置标准错误流以在运行系统命令时重定向到标准输出流。初始值为假。
参数 | |
---|---|
redirect | boolean :是否重定向的新值 |
设置工作目录
public abstract void setWorkingDir (File dir)
设置系统命令的工作目录。
参数 | |
---|---|
dir | File :工作目录 |
睡觉
public abstract void sleep (long time)
帮助程序方法在给定时间内休眠,忽略任何异常。
参数 | |
---|---|
time | long :女士要睡觉了。小于或等于 0 的值将被忽略 |
取消设置环境变量
public abstract void unsetEnvVariable (String key)
取消设置环境变量,因此系统命令在没有此环境变量的情况下运行。
参数 | |
---|---|
key | String :变量名 |
也可以看看:
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-07-19。