def process = "ls -l".execute()
println "Found text ${process.text}"
Run Code Online (Sandbox Code Playgroud)
是否有一个简洁的等价物来获取错误流?
您可以使用waitForProcessOutput哪两个Appendables(这里的文档)
def process = "ls -l".execute()
def (output, error) = new StringWriter().with { o -> // For the output
new StringWriter().with { e -> // For the error stream
process.waitForProcessOutput( o, e )
[ o, e ]*.toString() // Return them both
}
}
// And print them out...
println "OUT: $output"
println "ERR: $error"
Run Code Online (Sandbox Code Playgroud)