2010-02-24 100 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