这里用到一个第三方的包,是github开源的
地址在这https://github.com/zeroturnaround/zt-exec
maven依赖
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-exec</artifactId>
<version>1.11</version>
</dependency>
参考代码如下
public void newInvokeShell(String...paramters) throws InterruptedException, TimeoutException, IOException {
new ProcessExecutor().command(paramters)
.redirectOutput(new LogOutputStream() {
@Override
protected void processLine(String line) {
if(line.contains("Submitted application")) {
xxx=line.substring(line.indexOf("application_"));
}
}
})
.execute();
}
他有很多种方式可以选择,具体可以看github的文档
本文介绍了一个GitHub上的开源项目Zeroturnaround ZT-Exec,该包可在Java中轻松调用Shell命令。通过Maven依赖引入后,提供了丰富的API来执行各种Shell操作,包括输出处理和错误管理。
6951

被折叠的 条评论
为什么被折叠?



