2012-01-28 74 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