API 文档 | 执行 |
---|
执行命令行进程。示例
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(args) | 为要执行的命令添加参数。 |
args(args) | 为要执行的命令添加参数。 |
commandLine(args) | 设置完整的命令行,包括要执行的可执行文件及其参数。 |
commandLine(arguments) | 设置完整的命令行,包括要执行的可执行文件及其参数。 |
environment(name, value) | 向此进程的环境中添加一个环境变量。 |
environment(environmentVariables) | 向此进程的环境中添加一些环境变量。 |
executable(executable) | 设置要使用的可执行文件的名称。 |
workingDir(dir) | 设置进程的工作目录。提供的参数按照 |
List
<CommandLineArgumentProvider
>
argumentProviders
(只读)
List
<CommandLineArgumentProvider
>应用程序的参数提供者。
OutputStream
errorOutput
用于从执行命令的进程中读取标准错误输出的输出流。默认为 System.err
。
String
executable
要使用的可执行文件的名称。
Provider
<ExecResult
>
executionResult
Provider
<ExecResult
>此任务运行的命令的结果。如果此任务尚未执行,则提供程序没有值。
InputStream
standardInput
用于执行命令的进程的标准输入流。进程完成后流将关闭。默认为空流。
OutputStream
standardOutput
用于从执行命令的进程中读取标准输出的输出流。默认为 System.out
。
File
workingDir
进程的工作目录。默认为项目目录。
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)
设置进程的工作目录。提供的参数按照 Project.file(java.lang.Object)
进行评估。