- bropen.toolkit.utils.os.Executor
-
执行系统命令。
示例:
import bropen.toolkit.utils.os.Executor;
def exc = new Executor( command: "ls -l", workingDirectory:"/", arguments:["/usr"], catchOutput: true );
println exc.run()
println exc.getOutput()
println exc.getError()
println exc.isFailure()
Windows下,如果无法执行一些自带的命令,可以尝试给命令加前缀“cmd /C ”。
-
-
Properties Summary
Properties
Type |
Name and description |
List<String> |
arguments 命令行参数,会直接拼到命令行后面 |
boolean |
catchOutput 是否要捕获执行输出信息,然后可以通过 getOutput、getError 获得 |
String |
command 命令行,如“ls” |
Map<String, String> |
environment 环境变量 |
List<Integer> |
exitValues 执行成功的退出码:默认为0 |
String |
outputCharset 输出信息的字符集,默认为当前系统字符集 |
long |
timeout 超时等待,单位毫秒,超时后自动杀进程 |
String |
workingDirectory 工作目录 |
-
Methods Summary
Methods
Type |
Name and description |
String |
getError() 如果设置了 catchOutput,则可以获得命令的错误输出信息 |
String |
getOutput() 如果设置了 catchOutput,则可以获得命令的输出信息 |
Boolean |
isFailure() 根据程序的退出码,判断是否执行 |
Boolean |
isKilled() 如果设置了 timeout,可用来判断是不是超时被杀死的 |
Integer |
run() 运行并返回退出码 |
-
Inherited Methods Summary
Inherited Methods
Methods inherited from class |
Name |
class Object |
Object#wait(long), Object#wait(long, int), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll() |
-
-
Property Detail
-
List<String> arguments
命令行参数,会直接拼到命令行后面
-
Map<String, String> environment
环境变量
-
List<Integer> exitValues
执行成功的退出码:默认为0
-
String outputCharset
输出信息的字符集,默认为当前系统字符集
-
long timeout
超时等待,单位毫秒,超时后自动杀进程
-
String workingDirectory
工作目录
-
Method Detail
-
Boolean isFailure()
根据程序的退出码,判断是否执行
- Returns:
- 如果执行返回true,否则返回false
-
Integer run()
运行并返回退出码
- Returns:
- exitValue
BROPEN Documentation, 2015-08-08 15:56