Exec

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

從執行命令的程序取用標準錯誤的輸出流。預設為 System.err

executable

要使用的可執行檔名稱。

executionResult

此 task 執行的命令的結果。如果此 task 尚未執行,則 provider 沒有值。

ignoreExitValue

指示是否忽略非零的結束值,或拋出例外。預設為 false

standardInput

執行命令的程序的標準輸入流。流在程序完成後關閉。預設為空流。

standardOutput

從執行命令的程序取用標準輸出的輸出流。預設為 System.out

workingDir

程序的 working directory。預設為專案目錄。

方法

方法描述
args(args)

為要執行的命令添加引數。

args(args)

為要執行的命令添加引數。

commandLine(args)

設定完整的命令列,包括要執行的可執行檔及其引數。

commandLine(arguments)

設定完整的命令列,包括要執行的可執行檔及其引數。

environment(name, value)

為此程序的環境添加一個環境變數。

environment(environmentVariables)

為此程序的環境添加一些環境變數。

executable(executable)

設定要使用的可執行檔名稱。

workingDir(dir)

設定程序的 working directory。提供的引數會根據 Project.file(java.lang.Object) 進行評估。

腳本區塊

沒有腳本區塊

屬性詳細資訊

List<String> args

要執行的命令的引數。預設為空列表。

List<CommandLineArgumentProvider> argumentProviders (唯讀)

應用程式的引數提供者。

List<String> commandLine

完整的命令列,包含可執行檔及其引數。

Map<String, Object> environment

程序要使用的環境變數。預設為此程序的環境。

OutputStream errorOutput

從執行命令的程序取用標準錯誤的輸出流。預設為 System.err

String executable

要使用的可執行檔名稱。

Provider<ExecResult> executionResult

此 task 執行的命令的結果。如果此 task 尚未執行,則 provider 沒有值。

boolean ignoreExitValue

指示是否忽略非零的結束值,或拋出例外。預設為 false

InputStream standardInput

執行命令的程序的標準輸入流。流在程序完成後關閉。預設為空流。

OutputStream standardOutput

從執行命令的程序取用標準輸出的輸出流。預設為 System.out

File workingDir

程序的 working directory。預設為專案目錄。

方法詳細資訊

T args(Iterable<?> args)

為要執行的命令添加引數。

T args(Object... args)

為要執行的命令添加引數。

T commandLine(Iterable<?> args)

設定完整的命令列,包括要執行的可執行檔及其引數。

T commandLine(Object... arguments)

設定完整的命令列,包括要執行的可執行檔及其引數。

T environment(String name, Object value)

為此程序的環境添加一個環境變數。

T environment(Map<String, ?> environmentVariables)

為此程序的環境添加一些環境變數。

T executable(Object executable)

設定要使用的可執行檔名稱。

T workingDir(Object dir)

設定程序的 working directory。提供的引數會根據 Project.file(java.lang.Object) 進行評估。