RunUtil
public
class
RunUtil
extends Object
implements
IRunUtil
java.lang.Object | |
↳ | com.android.tradefed.util.RunUtil |
用于执行操作的辅助方法的集合。
摘要
字段 | |
---|---|
public
static
final
String |
INHERITIO_PREFIX
|
public
static
final
String |
RUNNABLE_NOTIFIER_NAME
|
公共构造函数 | |
---|---|
RunUtil()
创建要使用的新 |
公共方法 | |
---|---|
void
|
allowInterrupt(boolean allow)
允许/禁止在当前线程上运行中断。 |
static
IRunUtil
|
getDefault()
获取对默认 |
void
|
interrupt(Thread thread, String message, ErrorIdentifier errorId)
中断指定线程上正在进行/即将进行的运行操作。 |
void
|
interrupt(Thread thread, String message)
中断指定线程上正在进行/即将进行的运行操作。 |
boolean
|
isInterruptAllowed()
提供 RunUtil 的中断状态。 |
Process
|
runCmdInBackground(Redirect redirect,
另一个 |
Process
|
runCmdInBackground(
另一个 |
Process
|
runCmdInBackground(
使用 |
Process
|
runCmdInBackground(String... command)
用于异步执行系统命令的辅助方法。 |
Process
|
runCmdInBackground(Redirect redirect, String... command)
用于异步执行系统命令的辅助方法。 |
boolean
|
runEscalatingTimedRetry(long opTimeout, long initialPollInterval, long maxPollInterval, long maxTime, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。 |
boolean
|
runFixedTimedRetry(long opTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。 |
boolean
|
runFixedTimedRetryWithOutputMonitor(long opTimeout, long idleOutputTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。 |
CommandStatus
|
runTimed(long timeout, IRunUtil.IRunnableResult runnable, boolean logErrors)
阻塞并执行操作,如果所需时间超过指定时间,则中止。 |
CommandResult
|
runTimedCmd(long timeout, OutputStream stdout, OutputStream stderr, String... command)
一种辅助方法,用于执行系统命令;如果所用时间超过指定时间,则中止,并将输出重定向到文件(如果已指定)。 |
CommandResult
|
runTimedCmd(long timeout, String... command)
用于执行系统命令,并在花费的时间超过指定时间时中止的辅助方法。 |
CommandResult
|
runTimedCmdRetry(long timeout, long retryInterval, int attempts, String... command)
用于执行系统命令,并在花费的时间超过指定时间时中止的辅助方法。 |
CommandResult
|
runTimedCmdRetryWithOutputMonitor(long timeout, long idleOutputTimeout, long retryInterval, int attempts, String... command)
用于执行系统命令,并在花费的时间超过指定时间时中止的辅助方法。 |
CommandResult
|
runTimedCmdSilently(long timeout, String... command)
用于执行系统命令,并在花费的时间超过指定时间时中止的辅助方法。 |
CommandResult
|
runTimedCmdSilentlyRetry(long timeout, long retryInterval, int attempts, String... command)
用于执行系统命令,并在花费的时间超过指定时间时中止的辅助方法。 |
CommandResult
|
runTimedCmdWithInput(long timeout, String input, File stdoutFile, File stderrFile, String... command)
一种辅助方法,用于执行系统命令;如果所用时间超过指定时间,则中止,并将输出重定向到文件(如果已指定)。 |
CommandResult
|
runTimedCmdWithInput(long timeout, String input, String... command)
一种辅助方法,用于执行需要 stdin 输入的系统命令,并在执行时间超过指定时间时中止系统命令。 |
CommandResult
|
runTimedCmdWithInput(long timeout, String input,
一种辅助方法,用于执行需要 stdin 输入的系统命令,并在执行时间超过指定时间时中止系统命令。 |
CommandResult
|
runTimedCmdWithInputRedirect(long timeout, File inputRedirect, String... command)
用于执行系统命令的辅助方法,该命令需要从文件中重定向标准输入文件,并在执行时间超过指定时间时中止它。 |
CommandResult
|
runTimedCmdWithOutputMonitor(long timeout, long idleOutputTimeout, OutputStream stdout, OutputStream stderr, String... command)
一种辅助方法,用于执行系统命令;如果所用时间超过指定时间,则中止,并将输出重定向到文件(如果已指定)。 |
CommandResult
|
runTimedCmdWithOutputMonitor(long timeout, long idleOutputTimeout, String... command)
用于执行系统命令,并在花费的时间超过指定时间时中止的辅助方法。 |
CommandResult
|
runTimedCmdWithOutputMonitor(long timeout, long idleOutputTimeout, OutputStream stdout, OutputStream stderr, ICacheClient cacheClient, String... command)
使用缓存执行系统命令的辅助方法。 |
boolean
|
runTimedRetry(long opTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。 |
boolean
|
runTimedRetryWithOutputMonitor(long opTimeout, long idleOutputTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。 |
CommandStatus
|
runTimedWithOutputMonitor(long timeout, long idleOutputTimeout, IRunUtil.IRunnableResult runnable, boolean logErrors)
阻塞并执行操作,如果所需时间超过指定时间,则中止。 |
void
|
setEnvVariable(String name, String value)
设置在运行系统命令时使用的环境变量。 |
void
|
setEnvVariablePriority(IRunUtil.EnvPriority priority)
决定是否在创建进程时取消设置环境变量的优先级高于设置环境变量。 |
void
|
setInterruptibleInFuture(Thread thread, long timeMs)
在等待一段时间后设置为可中断。 |
void
|
setLinuxInterruptProcess(boolean interrupt)
允许在 Linux 通过 #runTimed 方法运行的进程超时时“终止”中断。 |
void
|
setRedirectStderrToStdout(boolean redirect)
将标准错误流设置为在运行系统命令时重定向到标准输出流。 |
void
|
setWorkingDir(File dir)
设置系统命令的工作目录。 |
void
|
sleep(long time)
帮助程序方法在给定时间内休眠,忽略所有异常。 |
void
|
unsetEnvVariable(String key)
取消设置环境变量,以便系统命令在没有此环境变量的情况下运行。
环境变量可能继承自父级进程,因此我们需要从 |
字段
INHERITIO_PREFIX
public static final String INHERITIO_PREFIX
RUNNABLE_NOTIFIER_NAME
public static final String RUNNABLE_NOTIFIER_NAME
公共构造函数
公共方法
allowInterrupt(允许中断)
public void allowInterrupt (boolean allow)
允许/禁止在当前线程上运行中断。如果允许,则当前线程的运行操作可以通过 interrupt(Thread, String)
方法从其他线程中断。
参数 | |
---|---|
allow |
boolean :是否允许在当前线程上运行运行中断。 |
getDefault
public static IRunUtil getDefault ()
获取对默认 RunUtil
对象的引用。
这对于希望使用 IRunUtil 而不进行自定义的调用方非常有用。
建议确实需要自定义 IRunUtil 实例(即需要调用 setEnvVariable(String, String)
或 setWorkingDir(File)
)的调用方创建自己的副本。
返回 | |
---|---|
IRunUtil |
中断
public void interrupt (Thread thread, String message, ErrorIdentifier errorId)
中断指定线程上正在进行/即将进行的运行操作。给定线程上的运行操作将抛出 RunInterruptedException
。
参数 | |
---|---|
message |
String :RunInterruptedException 的消息。 |
errorId |
ErrorIdentifier :表示已知中断原因。 |
中断
public void interrupt (Thread thread, String message)
中断指定线程上正在进行/即将进行的运行操作。给定线程上的运行操作将抛出 RunInterruptedException
。
参数 | |
---|---|
message |
String :RunInterruptedException 的消息。 |
isInterruptAllowed
public boolean isInterruptAllowed ()
提供 RunUtil 的中断状态。
返回 | |
---|---|
boolean |
如果运行可以中断,则为 true,否则为 false。 |
运行 CmdInBackground
public Process runCmdInBackground (Redirect redirect,command)
另一个 runCmdInBackground(String)
方法,可接受 ERROR(/List)
形式的命令参数。
参数 | |
---|---|
redirect |
Redirect :要应用于 ProcessBuilder 的 ERROR(/Redirect) 。 |
command |
:包含指定系统命令以及 exec 的参数(可选)的 ERROR(/List) |
返回 | |
---|---|
Process |
已执行命令的 Process |
运行 CmdInBackground
public Process runCmdInBackground (command)
另一个 runCmdInBackground(String)
方法,可接受 ERROR(/List)
形式的命令参数。
参数 | |
---|---|
command |
:包含指定系统命令以及 exec 的参数(可选)的 ERROR(/List) |
返回 | |
---|---|
Process |
已执行命令的 Process |
运行 CmdInBackground
public Process runCmdInBackground (command, OutputStream output)
使用 ERROR(/OutputStream)
运行命令会记录命令的输出。stdout 和 stderr 会合并在一起。
参数 | |
---|---|
command |
:要运行的命令 |
output |
OutputStream :用于保存输出的 OutputStream |
返回 | |
---|---|
Process |
运行命令的 Process |
运行 CmdInBackground
public Process runCmdInBackground (String... command)
用于异步执行系统命令的辅助方法。
将在启动命令后立即返回。
参数 | |
---|---|
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
Process |
已执行命令的 Process |
运行 CmdInBackground
public Process runCmdInBackground (Redirect redirect, String... command)
用于异步执行系统命令的辅助方法。
将在启动命令后立即返回。
参数 | |
---|---|
redirect |
Redirect :要应用于 ProcessBuilder 的 ERROR(/Redirect) 。 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
Process |
已执行命令的 Process |
runEscalatingTimedRetry 返回
public 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 |
如果操作在 maxTime 过期之前成功完成,则为 true |
runFixedTimed 重试
public boolean runFixedTimedRetry (long opTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。
参数 | |
---|---|
opTimeout |
long :单次操作尝试的最长等待时间(以毫秒为单位) |
pollInterval |
long :两次操作尝试之间的初始等待时间 |
maxTime |
long :继续尝试操作的大致总时长上限 |
runnable |
IRunUtil.IRunnableResult :要执行的 IRunUtil.IRunnableResult |
返回 | |
---|---|
boolean |
如果操作在 maxTime 过期之前成功完成,则为 true |
runFixedTimedRetryWithOutputMonitor
public boolean runFixedTimedRetryWithOutputMonitor (long opTimeout, long idleOutputTimeout, long pollInterval, long maxTime, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。还会监控输出流中的活动,如果在指定时间内未观察到任何流活动,则中止。 如果将 idilOutputTimeout 值设为零,则不会发生音频流监控。
参数 | |
---|---|
opTimeout |
long :单次操作尝试的最长等待时间(以毫秒为单位) |
idleOutputTimeout |
long :输出流上输出等待的最长时间(以毫秒为单位) |
pollInterval |
long :两次操作尝试之间的初始等待时间 |
maxTime |
long :继续尝试操作的大致总时长上限 |
runnable |
IRunUtil.IRunnableResult :要执行的 IRunUtil.IRunnableResult |
返回 | |
---|---|
boolean |
如果操作在 maxTime 过期之前成功完成,则为 true |
runTimed 键
public CommandStatus runTimed (long timeout, IRunUtil.IRunnableResult runnable, boolean logErrors)
阻塞并执行操作,如果所需时间超过指定时间,则取消。
参数 | |
---|---|
timeout |
long :最长等待时间(毫秒) |
runnable |
IRunUtil.IRunnableResult :要执行的 IRunUtil.IRunnableResult |
logErrors |
boolean :记录异常与非异常相关的错误。 |
返回 | |
---|---|
CommandStatus |
运算的 CommandStatus 结果。 |
runTimedCmd
public CommandResult runTimedCmd (long timeout, OutputStream stdout, OutputStream stderr, String... command)
一种辅助方法,用于执行系统命令;如果所用时间超过指定时间,则中止,并将输出重定向到文件(如果已指定)。如果以这种方式提供 ERROR(/OutputStream)
,它们在函数结束时将保持打开状态。
参数 | |
---|---|
timeout |
long :超时最长等待时间(以毫秒为单位)。0 表示无超时。 |
stdout |
OutputStream :ERROR(/OutputStream) ,标准输出将被重定向到该位置。可以为 null。 |
stderr |
OutputStream :ERROR(/OutputStream) ,错误输出将被重定向到该位置。可以为 null。 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmd
public CommandResult runTimedCmd (long timeout, String... command)
用于执行系统命令的辅助方法,如果所用时间超过指定时间,则中止。
参数 | |
---|---|
timeout |
long :最长等待时间(以毫秒为单位)。0 表示无超时。 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmd 重试
public CommandResult runTimedCmdRetry (long timeout, long retryInterval, int attempts, String... command)
用于执行系统命令的辅助方法,如果所用时间超过指定时间,则中止。
参数 | |
---|---|
timeout |
long :每次尝试的最长等待时间(以毫秒为单位) |
retryInterval |
long :两次命令重试之间的等待时间 |
attempts |
int :尝试次数上限 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmd 使用输出监视器重试
public CommandResult runTimedCmdRetryWithOutputMonitor (long timeout, long idleOutputTimeout, long retryInterval, int attempts, String... command)
用于执行系统命令的辅助方法,如果所用时间超过指定时间,则中止。它还会监控输出流中的活动,如果在指定时间内未观察到任何流活动,则中止。如果空闲输出超时值设为零,则不会发生数据流监控。
参数 | |
---|---|
timeout |
long :每次尝试的最长等待时间(以毫秒为单位) |
idleOutputTimeout |
long :输出流上输出等待的最长时间(以毫秒为单位) |
retryInterval |
long :两次命令重试之间的等待时间 |
attempts |
int :尝试次数上限 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmdSilently(静默运行)
public CommandResult runTimedCmdSilently (long timeout, String... command)
用于执行系统命令的辅助方法,如果所用时间超过指定时间,则中止。与 runTimedCmd(long, String)
类似,但不记录任何异常错误。
参数 | |
---|---|
timeout |
long :最长等待时间(毫秒) |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmd 静默地重试
public 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 |
runTimedCmdWithInput(在输入时运行)
public CommandResult runTimedCmdWithInput (long timeout, String input, File stdoutFile, File stderrFile, String... command)
一种辅助方法,用于执行系统命令;如果所用时间超过指定时间,则中止,并将输出重定向到文件(如果已指定)。
参数 | |
---|---|
timeout |
long :超时最长等待时间(以毫秒为单位)。0 表示无超时。 |
input |
String :要传递给进程的 stdin 输入 |
stdoutFile |
File :ERROR(/File) ,标准输出将被重定向到该位置。可以为 null。 |
stderrFile |
File :ERROR(/File) ,错误输出将被重定向到该位置。可以为 null。 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmdWithInput(在输入时运行)
public CommandResult runTimedCmdWithInput (long timeout, String input, String... command)
一种辅助方法,用于执行需要 stdin 输入的系统命令,并在执行时间超过指定时间时中止系统命令。
参数 | |
---|---|
timeout |
long :最长等待时间(毫秒) |
input |
String :要传递给进程的 stdin 输入 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmdWithInput(在输入时运行)
public CommandResult runTimedCmdWithInput (long timeout, String input,command)
一种辅助方法,用于执行需要 stdin 输入的系统命令,并在执行时间超过指定时间时中止系统命令。
参数 | |
---|---|
timeout |
long :最长等待时间(毫秒) |
input |
String :要传递给进程的 stdin 输入 |
command |
:包含系统命令和 exec(可选)参数的 ERROR(/List) |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmdWithInputRedirect 类
public CommandResult runTimedCmdWithInputRedirect (long timeout, File inputRedirect, String... command)
用于执行系统命令的辅助方法,该命令要求从文件重定向标准输入,并在耗时超过指定时间时中止。
参数 | |
---|---|
timeout |
long :最长等待时间(毫秒) |
inputRedirect |
File :使用 ProcessBuilder.redirectInput() 作为标准输入重定向的 ERROR(/File) 。如果为 null,stdin 将不会进行重定向。 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmdWithOutputMonitor
public CommandResult runTimedCmdWithOutputMonitor (long timeout, long idleOutputTimeout, OutputStream stdout, OutputStream stderr, String... command)
一种辅助方法,用于执行系统命令;如果所用时间超过指定时间,则中止,并将输出重定向到文件(如果已指定)。如果以这种方式提供 ERROR(/OutputStream)
,它们在函数结束时将保持打开状态。
参数 | |
---|---|
timeout |
long :超时最长等待时间(以毫秒为单位)。0 表示无超时。 |
idleOutputTimeout |
long :输出流上输出等待的最长时间(以毫秒为单位) |
stdout |
OutputStream :ERROR(/OutputStream) ,标准输出将被重定向到该位置。可以为 null。 |
stderr |
OutputStream :ERROR(/OutputStream) ,错误输出将被重定向到该位置。可以为 null。 |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmdWithOutputMonitor
public CommandResult runTimedCmdWithOutputMonitor (long timeout, long idleOutputTimeout, String... command)
用于执行系统命令的辅助方法,如果所用时间超过指定时间,则中止。它还会监控输出流中的活动,如果在指定时间内未观察到任何流活动,则中止。如果空闲输出超时值设为零,则不会发生数据流监控。
参数 | |
---|---|
timeout |
long :最长等待时间(以毫秒为单位)。0 表示无超时。 |
idleOutputTimeout |
long :输出流上输出等待的最长时间(以毫秒为单位) |
command |
String :指定的系统命令和 exec 的可选参数 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult |
runTimedCmdWithOutputMonitor
public CommandResult runTimedCmdWithOutputMonitor (long timeout, long idleOutputTimeout, OutputStream stdout, OutputStream stderr, ICacheClient cacheClient, String... command)
使用缓存执行系统命令的辅助方法。
如果指定 cacheClient
,则将启用缓存。如果缓存可用,将返回缓存的结果。否则,系统将使用 runTimedCmdWithOutputMonitor(long, long, OutputStream, OutputStream, String)
来执行该命令,并上传结果以进行缓存。
参数 | |
---|---|
timeout |
long :超时最长等待时间(以毫秒为单位)。0 表示无超时。 |
idleOutputTimeout |
long :输出流上输出等待的最长时间(以毫秒为单位)。 |
stdout |
OutputStream :ERROR(/OutputStream) ,标准输出将被重定向到该位置。可以为 null。 |
stderr |
OutputStream :ERROR(/OutputStream) ,错误输出将被重定向到该位置。可以为 null。 |
cacheClient |
ICacheClient :用于处理缓存的 ICacheClient 实例。 |
command |
String :指定的系统命令和 exec 的可选参数。 |
返回 | |
---|---|
CommandResult |
包含命令运行结果的 CommandResult 。 |
runTimedRetry [运行时间重试]
public boolean runTimedRetry (long opTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。
参数 | |
---|---|
opTimeout |
long :一次操作尝试等待的最长时间(以毫秒为单位) |
pollInterval |
long :两次命令重试之间的等待时间 |
attempts |
int :尝试次数上限 |
runnable |
IRunUtil.IRunnableResult :要执行的 IRunUtil.IRunnableResult |
返回 | |
---|---|
boolean |
如果操作在达到尝试次数之前成功完成,则为 true 。 |
runTimedRetryWithOutputMonitor
public boolean runTimedRetryWithOutputMonitor (long opTimeout, long idleOutputTimeout, long pollInterval, int attempts, IRunUtil.IRunnableResult runnable)
多次阻塞并执行操作,直到成功。还会监控输出流中的活动,如果在指定时间内未观察到任何流活动,则中止。 如果将 idilOutputTimeout 值设为零,则不会发生音频流监控。
参数 | |
---|---|
opTimeout |
long :一次操作尝试等待的最长时间(以毫秒为单位) |
idleOutputTimeout |
long :输出流上输出等待的最长时间(以毫秒为单位) |
pollInterval |
long :两次命令重试之间的等待时间 |
attempts |
int :尝试次数上限 |
runnable |
IRunUtil.IRunnableResult :要执行的 IRunUtil.IRunnableResult |
返回 | |
---|---|
boolean |
如果操作在达到尝试次数之前成功完成,则为 true 。 |
runTimedWithOutputMonitor
public CommandStatus runTimedWithOutputMonitor (long timeout, long idleOutputTimeout, IRunUtil.IRunnableResult runnable, boolean logErrors)
阻塞并执行操作,如果所需时间超过指定时间,则取消。它还会监控输出流中的活动,如果在指定时间内未观察到任何流活动,则中止。如果将 idilOutputTimeout 值设为零,则不会发生音频流监控。
参数 | |
---|---|
timeout |
long :最长等待时间(毫秒) |
idleOutputTimeout |
long :输出流上输出等待的最长时间(以毫秒为单位) |
runnable |
IRunUtil.IRunnableResult :要执行的 IRunUtil.IRunnableResult |
logErrors |
boolean :记录异常与非异常相关的错误。 |
返回 | |
---|---|
CommandStatus |
运算的 CommandStatus 结果。 |
setEnvVariable
public void setEnvVariable (String name, String value)
设置在运行系统命令时使用的环境变量。
参数 | |
---|---|
name |
String :变量名称 |
value |
String :变量值 |
setEnvVariablePriority
public void setEnvVariablePriority (IRunUtil.EnvPriority priority)
确定在创建进程时是否取消设置环境变量的优先级高于设置环境变量。默认情况下,取消设置优先级较高:这意味着,如果尝试设置具有相同名称的变量,则不会发生这种情况,因为未设置该变量。无法用于默认的“IRunUtil
”实例。
参数 | |
---|---|
priority |
IRunUtil.EnvPriority |
setInterruptibleInFuture
public void setInterruptibleInFuture (Thread thread, long timeMs)
在等待一段时间后设置为可中断。
ERROR(/CommandScheduler#shutdownHard())
来强制执行,我们最终会终止。
参数 | |
---|---|
thread |
Thread :将变为可中断的线程。 |
timeMs |
long :在设置可中断之前等待的时间。 |
setLinuxInterruptProcess
public void setLinuxInterruptProcess (boolean interrupt)
允许在 Linux 通过 #runTimed 方法运行的进程超时时“终止”中断。
无法用于默认的“IRunUtil
”实例。
参数 | |
---|---|
interrupt |
boolean |
setRedirectStderrToStdout
public void setRedirectStderrToStdout (boolean redirect)
将标准错误流设置为在运行系统命令时重定向到标准输出流。初始值为 false。
参数 | |
---|---|
redirect |
boolean :用于指定是否重定向的新值 |
setWORKDir
public void setWorkingDir (File dir)
设置系统命令的工作目录。
参数 | |
---|---|
dir |
File :工作目录 |
sleep
public void sleep (long time)
帮助程序方法在给定时间内休眠,忽略所有异常。
参数 | |
---|---|
time |
long :休眠 ms。小于或等于 0 的值将被忽略 |
UnsetEnvVariable
public void unsetEnvVariable (String key)
取消设置环境变量,以便系统命令在没有此环境变量的情况下运行。
环境变量可能继承自父级进程,因此我们需要从 ProcessBuilder.environment()
中删除环境变量
参数 | |
---|---|
key |
String :变量名称 |