Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

capturing exit code
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

Report this thread to moderator Post Follow-up to this message
Old Post
dafella24
09-25-04 01:57 AM


Re: capturing exit code
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

Report this thread to moderator Post Follow-up to this message
Old Post
Heiko
09-25-04 02:00 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:22 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.