2012-01-28 38 views
1

当我做类似如下:获取系统调用的错误输出?

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

但是,当...

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

我怎样才能得到系统调用的错误输出?

回答

4

我找到了答案。输出被发送到stderr。这样我就可以添加以下内容在命令的最后重定向错误输出到标准输出:

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

Here is the explanation of this witchcraft