当我执行以下操作时:
output = `identify some_file`
output == "Output of identify"
Run Code Online (Sandbox Code Playgroud)
但当...
output = `identify non_existant_file`
output != "Error output of identify"
Run Code Online (Sandbox Code Playgroud)
如何获得系统调用的错误输出?
我找到了答案。输出将发送到stderr。因此,我可以在命令末尾添加以下内容以将stderr重定向到stdout:
output = `identify any_file 2>&1`
output == "Error or output of identify"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2346 次 |
| 最近记录: |