gpt4 book ai didi

ruby - 获取系统调用的错误输出?

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:48 26 4
gpt4 key购买 nike

当我执行以下操作时:

output = `identify some_file`
output == "Output of identify"

但是当...

output = `identify non_existant_file`
output != "Error output of identify"

如何获取系统调用的错误输出?

最佳答案

我找到了答案。输出被发送到 stderr。所以我可以在命令末尾添加以下内容以将 stderr 重定向到 stdout:

output = `identify any_file 2>&1`
output == "Error or output of identify"

Here is the explanation of this witchcraft

关于ruby - 获取系统调用的错误输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9044209/

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