For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2004 > capturing exit code









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author capturing exit code
dafella24

2004-09-24, 8:57 pm

here is the code:

while true
do
trap INT HUP
../foo
ret=$?

echo $ret
fi
done

and here is the question?

foo is a c program which will be in a block state after running it.
When you do ctr-c foo comes out and returns 1. But the return code is
130 which is the exit for ctr-c for the script. Any way I can capture
the return code for the program when I do ctr-c instead of the exit
code of the script.

Thanks
Heiko

2004-09-25, 9:00 am

dafella24 wrote:

> here is the code:
>
> while true
> do
> trap INT HUP
> ./foo
> ret=$?
>
> echo $ret
> fi
> done


It's not clear to me what you would like "trap INT HUP" to do exactly
in this script code.

> foo is a c program which will be in a block state after running it.
> When you do ctr-c foo comes out and returns 1. But the return code is
> 130 which is the exit for ctr-c for the script. Any way I can capture
> the return code for the program when I do ctr-c instead of the exit
> code of the script.


So "foo" catches SIGINT. Then does just this work for your purpose?

while true ; do
./foo
ret=$?
echo $ret
done

Or, if you wat to prevent the script itself being INTerrupted, add a
"trap" to ignore ctrl-c inside the script:

while true ; do
trap "" INT
./foo
ret=$?
echo $ret
done

Regards,

Heiko
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com