gpt4 book ai didi

groovy - process.text 的错误等效项?

转载 作者:行者123 更新时间:2023-12-02 06:23:12 36 4
gpt4 key购买 nike

You can get the entire output stream通过使用.text:

def process = "ls -l".execute()
println "Found text ${process.text}"

是否有一个简洁的等效方法来获取错误流?

最佳答案

您可以使用 waitForProcessOutput ,它需要两个 Appendables ( docs here )

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"

关于groovy - process.text 的错误等效项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10688688/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com