views:

184

answers:

3

Hello folks,

One of the binaries which I am using in my shell script is causing a segmentation fault (RETURN VALUE: 139)

And even though, I am redirecting both stdout and stderr to a logfile, the Segmentation Fault error messages is displayed in the terminal when I am running the shell script.

Is it possible to redirect this message from Segfault to a logfile ??

A: 

try

./program &> logfile

there are various exampls on I/O redirection here, have a look

You can take a look at this discussion as well

ghostdog74
Kiran
http://stackoverflow.com/questions/988279/bash-redirecting-of-stdoutput-and-stderror-does-not-catch-all-outputI am looking at a similar approach.. but within a shell script
Kiran
you can see http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2004-12/0135.html for a discussion
ghostdog74
I got the solution here :http://stackoverflow.com/questions/416351/how-can-i-suppress-the-output-due-to-a-sigsegv-or-a-sigfpe-in-a-fortran-90-progra/416433The trick is to add exec 2> <filename>Thanks againkrian
Kiran
A: 

The Segmentation Fault message you see is printed by the shell that is running your program. This behavior varies from shell to shell, so a few things you could try (if you insist on getting the segmentation fault message into your logs from shell-redirects).

# 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
Kjetil Jorgensen
+1  A: 

Well, I am answering my own question.. :) I found the answer here http://stackoverflow.com/questions/416351/how-can-i-suppress-the-output-due-to-a-sigsegv-or-a-sigfpe-in-a-fortran-90-progra/416433

The trick is to add

`exec 2> filename`  

in the shell script.

This will redirect all the messages from the shell to a log file

Kiran