運行工具

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 ()

建立一個新的RunUtil物件來使用。

公共方法

void allowInterrupt (boolean allow)

允許/禁止當前執行緒上的運行中斷。

static IRunUtil getDefault ()

取得預設RunUtil物件的參考。

void interrupt (Thread thread, String message, ErrorIdentifier errorId)

中斷給定線程上正在進行/即將進行的運行操作。

void interrupt (Thread thread, String message)

中斷給定線程上正在進行/即將進行的運行操作。

boolean isInterruptAllowed ()

給予 RunUtil 的中斷狀態。

Process runCmdInBackground (Redirect redirect, command) runCmdInBackground (Redirect redirect, command)

另一個runCmdInBackground(String)方法,它接受ERROR(/List)形式的指令參數。

Process runCmdInBackground ( command) runCmdInBackground ( command)

另一個runCmdInBackground(String)方法,它接受ERROR(/List)形式的指令參數。

Process runCmdInBackground ( command, OutputStream output) runCmdInBackground ( command, OutputStream output)

執行帶有ERROR(/OutputStream)的命令會記錄命令的輸出。

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, command) runTimedCmdWithInput (long timeout, String input, command)

用於執行需要 stdin 輸入的系統命令的幫助程序方法,如果花費的時間超過指定時間,則中止。

CommandResult runTimedCmdWithInputRedirect (long timeout, File inputRedirect, String... command)

用於執行需要從檔案重新導向 Stdin 的系統指令的幫助程式方法,如果花費的時間超過指定時間,則中止。

CommandResult runTimedCmdWithOutputMonitor (long timeout, long idleOutputTimeout, OutputStream stdout, OutputStream stderr, String... command)

用於執行系統命令的幫助程序方法,如果花費的時間超過指定時間則中止,並將輸出重定向到檔案(如果指定)。

CommandResult runTimedCmdWithOutputMonitor (long timeout, long idleOutputTimeout, 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)

允許在逾時時對透過 #runTimed 方法執行的程序使用 linux「kill」中斷。

void setRedirectStderrToStdout (boolean redirect)

設定標準錯誤流以在執行系統命令時重定向到標準輸出流。

void setWorkingDir (File dir)

設定係統指令的工作目錄。

void sleep (long time)

幫助程序方法在給定時間內休眠,忽略任何異常。

void unsetEnvVariable (String key)

取消設定環境變量,因此系統命令在沒有此環境變量的情況下運行。環境變數可能繼承自父進程,因此我們需要從ProcessBuilder.environment()中刪除環境變數

領域

繼承前綴

public static final String INHERITIO_PREFIX

RUNNABLE_NOTIFIER_NAME

public static final String RUNNABLE_NOTIFIER_NAME

公共構造函數

運行工具

public RunUtil ()

建立一個新的RunUtil物件來使用。

公共方法

允許中斷

public void allowInterrupt (boolean allow)

允許/禁止當前執行緒上的運行中斷。如果允許,可以透過interrupt(Thread, String)方法從其他執行緒中斷目前執行緒的運行操作。

參數
allow boolean : 是否允許目前執行緒運行中斷。

取得預設值

public static IRunUtil getDefault ()

取得預設RunUtil物件的參考。

這對於想要使用 IRunUtil 而不進行自訂的呼叫者非常有用。建議確實需要自訂 IRunUtil 實例(即需要呼叫setEnvVariable(String, String)setWorkingDir(File)呼叫者建立自己的副本。

退貨
IRunUtil

打斷

public void interrupt (Thread thread, 
                String message, 
                ErrorIdentifier errorId)

中斷給定線程上正在進行/即將進行的運行操作。給定執行緒上的運行操作將會拋出RunInterruptedException

參數
message StringRunInterruptedException的訊息。

errorId ErrorIdentifier :表示已知的中斷原因。

打斷

public void interrupt (Thread thread, 
                String message)

中斷給定線程上正在進行/即將進行的運行操作。給定執行緒上的運行操作將會拋出RunInterruptedException

參數
message StringRunInterruptedException的訊息。

允許中斷

public boolean isInterruptAllowed ()

給予 RunUtil 的中斷狀態。

退貨
boolean如果運行可以中斷,則為 true,否則為 false。

運行CmdInBackground

public Process runCmdInBackground (Redirect redirect, 
                 command)

另一個runCmdInBackground(String)方法,它接受ERROR(/List)形式的指令參數。

參數
redirect Redirect :應用於ProcessBuilder ERROR(/Redirect)

command : ERROR(/List)包含指定的系統指令和可選的 exec 參數

退貨
Process執行命令的Process

運行CmdInBackground

public Process runCmdInBackground ( command)

另一個runCmdInBackground(String)方法,它接受ERROR(/List)形式的指令參數。

參數
command : ERROR(/List)包含指定的系統指令和可選的 exec 參數

退貨
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

運行升級定時重試

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 true如果操作在 maxTime 過期之前成功完成

運行固定定時重試

public 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 過期之前成功完成

runFixedTimedRetryWithOutputMonitor

public boolean runFixedTimedRetryWithOutputMonitor (long opTimeout, 
                long idleOutputTimeout, 
                long pollInterval, 
                long maxTime, 
                IRunUtil.IRunnableResult runnable)

多次阻塞並執行一個操作,直到成功。也會監視輸出流的活動,如果在指定時間內沒有觀察到流活動,則中止。如果idleOutputTimeout設定為零,則不會發生串流監控。

參數
opTimeout long :單次操作嘗試等待的最長時間(以毫秒為單位)

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

pollInterval long :操作嘗試之間等待的初始時間

maxTime long :繼續嘗試操作的總的近似最大時間

runnable IRunUtil.IRunnableResult :要執行的IRunUtil.IRunnableResult

退貨
boolean true如果操作在 maxTime 過期之前成功完成

運行時

public CommandStatus runTimed (long timeout, 
                IRunUtil.IRunnableResult runnable, 
                boolean logErrors)

阻止並執行操作,如果花費的時間超過指定時間則中止。

參數
timeout long :等待的最長時間(以毫秒為單位)

runnable IRunUtil.IRunnableResult :要執行的IRunUtil.IRunnableResult

logErrors boolean :是否記錄異常錯誤。

退貨
CommandStatus CommandStatus操作結果。

運行定時命令

public 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 CommandResult runTimedCmd (long timeout, 
                String... command)

執行系統指令的幫助程序方法,如果花費的時間超過指定時間,則中止。

參數
timeout long :等待的最長時間(以毫秒為單位)。 0 表示沒有超時。

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

運行定時命令重試

public CommandResult runTimedCmdRetry (long timeout, 
                long retryInterval, 
                int attempts, 
                String... command)

執行系統指令的幫助程序方法,如果花費的時間超過指定時間,則中止。

參數
timeout long :每次嘗試等待的最長時間(以毫秒為單位)

retryInterval long :指令重試之間等待的時間

attempts int : 最大嘗試次數

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

runTimedCmdRetryWithOutputMonitor

public CommandResult runTimedCmdRetryWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                long retryInterval, 
                int attempts, 
                String... command)

執行系統指令的幫助程序方法,如果花費的時間超過指定時間,則中止。也會監視輸出流的活動,如果在指定時間內沒有觀察到流活動,則中止。如果idleOutputTimeout設定為零,則不會發生串流監控。

參數
timeout long :每次嘗試等待的最長時間(以毫秒為單位)

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

retryInterval long :指令重試之間等待的時間

attempts int : 最大嘗試次數

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

靜默運轉定時命令

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

帶輸入的運行定時命令

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                File stdoutFile, 
                File stderrFile, 
                String... command)

用於執行系統命令的幫助程序方法,如果花費的時間超過指定時間則中止,並將輸出重定向到檔案(如果指定)。

參數
timeout long :超時等待的最長時間(以毫秒為單位)。 0 表示沒有超時。

input String :傳遞給進程的標準輸入

stdoutFile FileERROR(/File)其中標準輸出將被重定向。可以為空。

stderrFile FileERROR(/File) ,錯誤輸出將被重定向。可以為空。

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

帶輸入的運行定時命令

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                String... command)

用於執行需要 stdin 輸入的系統命令的幫助程序方法,如果花費的時間超過指定時間,則中止。

參數
timeout long :等待的最長時間(以毫秒為單位)

input String :傳遞給進程的標準輸入

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

帶輸入的運行定時命令

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                 command)

用於執行需要 stdin 輸入的系統命令的幫助程序方法,如果花費的時間超過指定時間,則中止。

參數
timeout long :等待的最長時間(以毫秒為單位)

input String :傳遞給進程的標準輸入

command : ERROR(/List)包含系統指令和可選的 exec 參數

退貨
CommandResult包含命令運行結果的CommandResult

runTimedCmdWithInputRedirect

public 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 CommandResult runTimedCmdWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                OutputStream stdout, 
                OutputStream stderr, 
                String... command)

用於執行系統命令的幫助程序方法,如果花費的時間超過指定時間則中止,並將輸出重定向到檔案(如果指定)。當以這種方式提供ERROR(/OutputStream)時,它們將在函數末尾保持開啟。

參數
timeout long :超時等待的最長時間(以毫秒為單位)。 0 表示沒有超時。

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

stdout OutputStream : ERROR(/OutputStream)其中 std 輸出將會被重新導向。可以為空。

stderr OutputStream : ERROR(/OutputStream)錯誤輸出將會被重新導向。可以為空。

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

帶輸出監視器的運行定時命令

public CommandResult runTimedCmdWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                String... command)

執行系統指令的幫助程序方法,如果花費的時間超過指定時間,則中止。也會監視輸出流的活動,如果在指定時間內沒有觀察到流活動,則中止。如果idleOutputTimeout設定為零,則不會發生串流監控。

參數
timeout long :等待的最長時間(以毫秒為單位)。 0 表示沒有超時。

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

運行定時重試

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)

多次阻塞並執行一個操作,直到成功。也會監視輸出流的活動,如果在指定時間內沒有觀察到流活動,則中止。如果idleOutputTimeout設定為零,則不會發生串流監控。

參數
opTimeout long :一次操作嘗試等待的最長時間(以毫秒為單位)

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

pollInterval long :指令重試之間等待的時間

attempts int : 最大嘗試次數

runnable IRunUtil.IRunnableResult :要執行的IRunUtil.IRunnableResult

退貨
boolean如果操作在嘗試到達之前成功完成,則為true

帶輸出監視器的運轉定時

public CommandStatus runTimedWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                IRunUtil.IRunnableResult runnable, 
                boolean logErrors)

阻止並執行操作,如果花費的時間超過指定時間則中止。也會監視輸出流的活動,如果在指定時間內沒有觀察到流活動,則中止。如果idleOutputTimeout設定為零,則不會發生串流監控。

參數
timeout long :等待的最長時間(以毫秒為單位)

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

runnable IRunUtil.IRunnableResult :要執行的IRunUtil.IRunnableResult

logErrors boolean :是否記錄異常錯誤。

退貨
CommandStatus CommandStatus操作結果。

設定環境變數

public void setEnvVariable (String name, 
                String value)

設定運行系統指令時要使用的環境變數。

參數
name String :變數名

value String :變數值

設定環境變數優先權

public void setEnvVariablePriority (IRunUtil.EnvPriority priority)

決定在建立進程時是否取消設定環境變數的優先權高於設定它們。預設情況下,取消設定具有更高的優先權:這表示如果嘗試設定具有相同名稱的變量,則不會發生這種情況,因為該變數將被取消設定。不能在預設IRunUtil實例上使用。

參數
priority IRunUtil.EnvPriority

設定可中斷的未來

public void setInterruptibleInFuture (Thread thread, 
                long timeMs)

等待一段時間後設定為可中斷。 ERROR(/CommandScheduler#shutdownHard())強制我們最終終止。

參數
thread Thread :將變成可中斷的執行緒。

timeMs long :設定可中斷之前等待的時間。

設定Linux中斷行程

public void setLinuxInterruptProcess (boolean interrupt)

允許在逾時時對透過 #runTimed 方法執行的程序使用 linux「kill」中斷。不能在預設IRunUtil實例上使用。

參數
interrupt boolean

setRedirectStderrToStdout

public void setRedirectStderrToStdout (boolean redirect)

設定標準錯誤流以在執行系統命令時重定向到標準輸出流。初始值為假。

參數
redirect boolean :是否重定向的新值

設定工作目錄

public void setWorkingDir (File dir)

設定係統指令的工作目錄。

參數
dir File :工作目錄

睡覺

public void sleep (long time)

幫助程序方法在給定時間內休眠,忽略任何異常。

參數
time long :女士要睡覺了。小於或等於 0 的值將被忽略

取消設定環境變數

public void unsetEnvVariable (String key)

取消設定環境變量,因此系統命令在沒有此環境變量的情況下運行。環境變數可能繼承自父進程,因此我們需要從ProcessBuilder.environment()中刪除環境變數

參數
key String :變數名

也可以看看:

,

運行工具

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 ()

建立一個新的RunUtil物件來使用。

公共方法

void allowInterrupt (boolean allow)

允許/禁止當前執行緒上的運行中斷。

static IRunUtil getDefault ()

取得預設RunUtil物件的參考。

void interrupt (Thread thread, String message, ErrorIdentifier errorId)

中斷給定線程上正在進行/即將進行的運行操作。

void interrupt (Thread thread, String message)

中斷給定線程上正在進行/即將進行的運行操作。

boolean isInterruptAllowed ()

給予 RunUtil 的中斷狀態。

Process runCmdInBackground (Redirect redirect, command) runCmdInBackground (Redirect redirect, command)

另一個runCmdInBackground(String)方法,它接受ERROR(/List)形式的指令參數。

Process runCmdInBackground ( command) runCmdInBackground ( command)

另一個runCmdInBackground(String)方法,它接受ERROR(/List)形式的指令參數。

Process runCmdInBackground ( command, OutputStream output) runCmdInBackground ( command, OutputStream output)

執行帶有ERROR(/OutputStream)的命令會記錄命令的輸出。

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, command) runTimedCmdWithInput (long timeout, String input, command)

用於執行需要 stdin 輸入的系統命令的幫助程序方法,如果花費的時間超過指定時間,則中止。

CommandResult runTimedCmdWithInputRedirect (long timeout, File inputRedirect, String... command)

用於執行需要從檔案重新導向 Stdin 的系統指令的幫助程式方法,如果花費的時間超過指定時間,則中止。

CommandResult runTimedCmdWithOutputMonitor (long timeout, long idleOutputTimeout, OutputStream stdout, OutputStream stderr, String... command)

用於執行系統命令的幫助程序方法,如果花費的時間超過指定時間則中止,並將輸出重定向到檔案(如果指定)。

CommandResult runTimedCmdWithOutputMonitor (long timeout, long idleOutputTimeout, 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)

允許在逾時時對透過 #runTimed 方法執行的程序使用 linux「kill」中斷。

void setRedirectStderrToStdout (boolean redirect)

設定標準錯誤流以在執行系統命令時重定向到標準輸出流。

void setWorkingDir (File dir)

設定係統指令的工作目錄。

void sleep (long time)

幫助程序方法在給定時間內休眠,忽略任何異常。

void unsetEnvVariable (String key)

取消設定環境變量,因此系統命令在沒有此環境變量的情況下運行。環境變數可能繼承自父進程,因此我們需要從ProcessBuilder.environment()中刪除環境變數

領域

繼承前綴

public static final String INHERITIO_PREFIX

RUNNABLE_NOTIFIER_NAME

public static final String RUNNABLE_NOTIFIER_NAME

公共構造函數

運行工具

public RunUtil ()

建立一個新的RunUtil物件來使用。

公共方法

允許中斷

public void allowInterrupt (boolean allow)

允許/禁止當前執行緒上的運行中斷。如果允許,可以透過interrupt(Thread, String)方法從其他執行緒中斷目前執行緒的運行操作。

參數
allow boolean : 是否允許目前執行緒運行中斷。

取得預設值

public static IRunUtil getDefault ()

取得預設RunUtil物件的參考。

這對於想要使用 IRunUtil 而不進行自訂的呼叫者非常有用。建議確實需要自訂 IRunUtil 實例(即需要呼叫setEnvVariable(String, String)setWorkingDir(File)呼叫者建立自己的副本。

退貨
IRunUtil

打斷

public void interrupt (Thread thread, 
                String message, 
                ErrorIdentifier errorId)

中斷給定線程上正在進行/即將進行的運行操作。給定執行緒上的運行操作將會拋出RunInterruptedException

參數
message StringRunInterruptedException的訊息。

errorId ErrorIdentifier :表示已知的中斷原因。

打斷

public void interrupt (Thread thread, 
                String message)

中斷給定線程上正在進行/即將進行的運行操作。給定執行緒上的運行操作將會拋出RunInterruptedException

參數
message StringRunInterruptedException的訊息。

允許中斷

public boolean isInterruptAllowed ()

給予 RunUtil 的中斷狀態。

退貨
boolean如果運行可以中斷,則為 true,否則為 false。

運行CmdInBackground

public Process runCmdInBackground (Redirect redirect, 
                 command)

另一個runCmdInBackground(String)方法,它接受ERROR(/List)形式的指令參數。

參數
redirect Redirect :應用於ProcessBuilder ERROR(/Redirect)

command : ERROR(/List)包含指定的系統指令和可選的 exec 參數

退貨
Process執行命令的Process

運行CmdInBackground

public Process runCmdInBackground ( command)

另一個runCmdInBackground(String)方法,它接受ERROR(/List)形式的指令參數。

參數
command : ERROR(/List)包含指定的系統指令和可選的 exec 參數

退貨
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

運行升級定時重試

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 true如果操作在 maxTime 過期之前成功完成

運行固定定時重試

public 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 過期之前成功完成

runFixedTimedRetryWithOutputMonitor

public boolean runFixedTimedRetryWithOutputMonitor (long opTimeout, 
                long idleOutputTimeout, 
                long pollInterval, 
                long maxTime, 
                IRunUtil.IRunnableResult runnable)

多次阻塞並執行一個操作,直到成功。也會監視輸出流的活動,如果在指定時間內沒有觀察到流活動,則中止。如果idleOutputTimeout設定為零,則不會發生串流監控。

參數
opTimeout long :單次操作嘗試等待的最長時間(以毫秒為單位)

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

pollInterval long :操作嘗試之間等待的初始時間

maxTime long :繼續嘗試操作的總的近似最大時間

runnable IRunUtil.IRunnableResult :要執行的IRunUtil.IRunnableResult

退貨
boolean true如果操作在 maxTime 過期之前成功完成

運行時

public CommandStatus runTimed (long timeout, 
                IRunUtil.IRunnableResult runnable, 
                boolean logErrors)

阻止並執行操作,如果花費的時間超過指定時間則中止。

參數
timeout long :等待的最長時間(以毫秒為單位)

runnable IRunUtil.IRunnableResult :要執行的IRunUtil.IRunnableResult

logErrors boolean :是否記錄異常錯誤。

退貨
CommandStatus CommandStatus操作結果。

運行定時命令

public 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 CommandResult runTimedCmd (long timeout, 
                String... command)

執行系統指令的幫助程序方法,如果花費的時間超過指定時間,則中止。

參數
timeout long :等待的最長時間(以毫秒為單位)。 0 表示沒有超時。

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

運行定時命令重試

public CommandResult runTimedCmdRetry (long timeout, 
                long retryInterval, 
                int attempts, 
                String... command)

執行系統指令的幫助程序方法,如果花費的時間超過指定時間,則中止。

參數
timeout long :每次嘗試等待的最長時間(以毫秒為單位)

retryInterval long :指令重試之間等待的時間

attempts int : 最大嘗試次數

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

runTimedCmdRetryWithOutputMonitor

public CommandResult runTimedCmdRetryWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                long retryInterval, 
                int attempts, 
                String... command)

執行系統指令的幫助程序方法,如果花費的時間超過指定時間,則中止。也會監視輸出流的活動,如果在指定時間內沒有觀察到流活動,則中止。如果idleOutputTimeout設定為零,則不會發生串流監控。

參數
timeout long :每次嘗試等待的最長時間(以毫秒為單位)

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

retryInterval long :指令重試之間等待的時間

attempts int : 最大嘗試次數

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

靜默運轉定時命令

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

帶輸入的運行定時命令

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                File stdoutFile, 
                File stderrFile, 
                String... command)

用於執行系統命令的幫助程序方法,如果花費的時間超過指定時間則中止,並將輸出重定向到檔案(如果指定)。

參數
timeout long :超時等待的最長時間(以毫秒為單位)。 0 表示沒有超時。

input String :傳遞給進程的標準輸入

stdoutFile FileERROR(/File)其中標準輸出將被重定向。可以為空。

stderrFile FileERROR(/File) ,錯誤輸出將被重定向。可以為空。

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

帶輸入的運行定時命令

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                String... command)

用於執行需要 stdin 輸入的系統命令的幫助程序方法,如果花費的時間超過指定時間,則中止。

參數
timeout long :等待的最長時間(以毫秒為單位)

input String :傳遞給進程的標準輸入

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

帶輸入的運行定時命令

public CommandResult runTimedCmdWithInput (long timeout, 
                String input, 
                 command)

用於執行需要 stdin 輸入的系統命令的幫助程序方法,如果花費的時間超過指定時間,則中止。

參數
timeout long :等待的最長時間(以毫秒為單位)

input String :傳遞給進程的標準輸入

command : ERROR(/List)包含系統指令和可選的 exec 參數

退貨
CommandResult包含命令運行結果的CommandResult

runTimedCmdWithInputRedirect

public 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 CommandResult runTimedCmdWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                OutputStream stdout, 
                OutputStream stderr, 
                String... command)

用於執行系統命令的幫助程序方法,如果花費的時間超過指定時間則中止,並將輸出重定向到檔案(如果指定)。當以這種方式提供ERROR(/OutputStream)時,它們將在函數末尾保持開啟。

參數
timeout long :超時等待的最長時間(以毫秒為單位)。 0 表示沒有超時。

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

stdout OutputStream : ERROR(/OutputStream)其中 std 輸出將會被重新導向。可以為空。

stderr OutputStream : ERROR(/OutputStream)錯誤輸出將會被重新導向。可以為空。

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

帶輸出監視器的運行定時命令

public CommandResult runTimedCmdWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                String... command)

執行系統指令的幫助程序方法,如果花費的時間超過指定時間,則中止。也會監視輸出流的活動,如果在指定時間內沒有觀察到流活動,則中止。如果idleOutputTimeout設定為零,則不會發生串流監控。

參數
timeout long :等待的最長時間(以毫秒為單位)。 0 表示沒有超時。

idleOutputTimeout long :等待輸出流上的輸出的最長時間(以毫秒為單位)

command String : 指定的系統指令和 exec 的可選參數

退貨
CommandResult包含命令運行結果的CommandResult

運行定時重試

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)

阻止並執行多次操作,直到成功為止。也監視活動流以進行活動,如果在指定的時間內觀察到未觀察到的流活動,則中斷。如果將IDLEOUTPUTTIME OUT設定為零,則不會進行串流監視。

參數
opTimeout long :在MS上等待一次操作嘗試的最大時間

idleOutputTimeout long :MS上等待輸出在輸出流上的最大時間

pollInterval long :等待兩者之間的命令重新恢復

attempts int :嘗試的最大嘗試數量

runnable IRunUtil.IRunnableResultIRunUtil.IRunnableResult執行

退貨
boolean如果操作在嘗試之前成功完成, true

runtimedwithOutputmonitor

public CommandStatus runTimedWithOutputMonitor (long timeout, 
                long idleOutputTimeout, 
                IRunUtil.IRunnableResult runnable, 
                boolean logErrors)

阻止並執行一個操作,如果它花費的時間比指定的時間更長。也監視活動流以進行活動,如果在指定的時間內觀察到未觀察到的流活動,則中斷。如果將IDLEOUTPUTTIME OUT設定為零,則不會進行串流監視。

參數
timeout long :在MS中等待的最大時間

idleOutputTimeout long :MS上等待輸出在輸出流上的最大時間

runnable IRunUtil.IRunnableResultIRunUtil.IRunnableResult執行

logErrors boolean :異常是否對數字錯誤。

退貨
CommandStatus操作的CommandStatus結果。

setEnvariable

public void setEnvVariable (String name, 
                String value)

設定運行系統指令時要使用的環境變數。

參數
name String :變數名稱

value String :變數值

setEnvariable優先權

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“ Kill”中斷在#runtimed方法到達時透過#Runtimed方法運行的過程。不能在預設的IRunUtil實例上使用。

參數
interrupt boolean

setRedirectStderRtostDout

public void setRedirectStderrToStdout (boolean redirect)

在執行系統指令時,將標準錯誤流設定為重定向到標準輸出流。初始值是錯誤的。

參數
redirect boolean :是否重新導向的新價值

SetWorkingDir

public void setWorkingDir (File dir)

為系統指令設定工作目錄。

參數
dir File :工作目錄

睡覺

public void sleep (long time)

給定時間睡覺的輔助方法,忽略任何例外。

參數
time long :MS睡覺。小於或等於0的值將被忽略

不設定

public void unsetEnvVariable (String key)

unsets一個環境變量,因此系統命令在沒有此環境變量的情況下運行。環境變數可能會從父流程繼承,因此我們需要從ProcessBuilder.environment()刪除環境變數

參數
key String :變數名稱

也可以看看: