2010-02-24 105 views
2

一個我用我的shell腳本的二進制文件引起分段錯誤(返回值:139)檢查標準輸出或標準錯誤

而且即使,我重定向標準輸出和標準錯誤輸出到一個日誌文件,當我運行shell腳本時,終端中會顯示Segmentation Fault錯誤消息。

是否有可能從段錯誤此消息重定向到一個日誌文件?

回答

0

嘗試

./program &> logfile 

上有I/O重定向here各種exampls,看看

您可以在此discussion看看還有

+0

嗯,這ddid不行, 這裏是我的代碼,這是造成問題: 「$解碼器」 - 如果$ INPUT_FILE -of $ output_file >> $ log_file 2>&1 這是Segfault導致的輸出: ./decode.sh:line 292:15475分段錯誤「$ DECODER」$ IF input .. – Kiran 2010-02-24 11:03:18

+0

http://stackoverflow.com /問題/ 988279/bash的變向-的-stdoutput-和stderror - 不 - 不包羅萬象的輸出 我在看一個類似的方法..但內一個shell腳本 – Kiran 2010-02-24 11:23:19

+0

你可以看到http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2004-12/0135.html的討論 – ghostdog74 2010-02-24 11:37:54

2

你看到分段錯誤消息由運行程序的shell打印。這種行爲因shell而異,所以你可以嘗試一些東西(如果你堅持從shell重定向中將分段錯誤消息存入你的日誌中)。

# Have sh invoke your program, and redirect output from both sh and your program into logfile 
sh -c "program arguments more arguments" >logfile 2>&1 
# Force bash to not just exec your program (/bin/true part), and redirect output 
# from both bash and your program into logfile 
bash -c "/bin/true; program arguments more arguments" >logfile 2>&1 
+0

古樸典雅。 +1 – 2015-07-26 20:45:20