出于某种原因,从 groovy 运行 curl 会成功调用错误:
def command = ["curl", "-LO", "https://curl.se/download/curl-7.79.1.tar.gz"]
def process = command.execute()
StringWriter output = new StringWriter()
StringWriter error = new StringWriter()
process.waitForProcessOutput(output, error)
if(process.exitValue()) {
throw new Exception("$error")
}
println "EXIT CODE: ${process.exitValue()}"
println "OUT: $output"
println "-------------------------------------------"
println "ERROR: $error"
println output.toString()
运行上述给出:
EXIT CODE: 0
OUT:
-------------------------------------------
ERROR: % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 4047k 100 4047k 0 0 7266k 0 --:--:-- --:--:-- --:--:-- 7266k
为什么 groovyerror即使out在exitValue=0
?