API 文件 | Exec |
---|
執行命令列程序。範例
task stopTomcat(type:Exec) { workingDir '../tomcat/bin' //on windows: commandLine 'cmd.exe', '/d', '/c', 'stop.bat' //on linux commandLine './stop.sh' //store the output instead of printing to the console: standardOutput = new ByteArrayOutputStream() //extension method stopTomcat.output() can be used to obtain the output: ext.output = { return standardOutput.toString() } }
屬性 | 描述 |
args | 要執行的命令的引數。預設為空列表。 |
argumentProviders | 應用程式的引數提供者。 |
commandLine | 完整的命令列,包含可執行檔及其引數。 |
environment | 程序要使用的環境變數。預設為此程序的環境。 |
errorOutput | 從執行命令的程序取用標準錯誤的輸出流。預設為 |
executable | 要使用的可執行檔名稱。 |
executionResult | 此 task 執行的命令的結果。如果此 task 尚未執行,則 provider 沒有值。 |
ignoreExitValue | 指示是否忽略非零的結束值,或拋出例外。預設為 |
standardInput | 執行命令的程序的標準輸入流。流在程序完成後關閉。預設為空流。 |
standardOutput | 從執行命令的程序取用標準輸出的輸出流。預設為 |
workingDir | 程序的 working directory。預設為專案目錄。 |
方法 | 描述 |
args(args) | 為要執行的命令添加引數。 |
args(args) | 為要執行的命令添加引數。 |
commandLine(args) | 設定完整的命令列,包括要執行的可執行檔及其引數。 |
commandLine(arguments) | 設定完整的命令列,包括要執行的可執行檔及其引數。 |
environment(name, value) | 為此程序的環境添加一個環境變數。 |
environment(environmentVariables) | 為此程序的環境添加一些環境變數。 |
executable(executable) | 設定要使用的可執行檔名稱。 |
workingDir(dir) | 設定程序的 working directory。提供的引數會根據 |
List
<CommandLineArgumentProvider
>
argumentProviders
(唯讀)
List
<CommandLineArgumentProvider
>應用程式的引數提供者。
OutputStream
errorOutput
從執行命令的程序取用標準錯誤的輸出流。預設為 System.err
。
String
executable
要使用的可執行檔名稱。
Provider
<ExecResult
>
executionResult
Provider
<ExecResult
>此 task 執行的命令的結果。如果此 task 尚未執行,則 provider 沒有值。
InputStream
standardInput
執行命令的程序的標準輸入流。流在程序完成後關閉。預設為空流。
OutputStream
standardOutput
從執行命令的程序取用標準輸出的輸出流。預設為 System.out
。
File
workingDir
程序的 working directory。預設為專案目錄。
T
args
(Iterable
<?>
args)
Iterable
<?>為要執行的命令添加引數。
T
args
(Object
...
args)
Object
...為要執行的命令添加引數。
T
commandLine
(Iterable
<?>
args)
Iterable
<?>設定完整的命令列,包括要執行的可執行檔及其引數。
T
commandLine
(Object
...
arguments)
Object
...設定完整的命令列,包括要執行的可執行檔及其引數。
T
executable
(Object
executable)
設定要使用的可執行檔名稱。
T
workingDir
(Object
dir)
設定程序的 working directory。提供的引數會根據 Project.file(java.lang.Object)
進行評估。