Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Detecting C failure indication in tcsh shell

Detecting C failure indication in tcsh shell
Thread Tools
Mac Elite
Join Date: Oct 2001
Location: Internet
Status: Offline
Reply With Quote
Sep 9, 2002, 03:30 PM
 
Can anyone explain how I can detect a failure indication (return 1) in OS X's tcsh shell?

I am using C.
     
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status: Offline
Reply With Quote
Sep 9, 2002, 05:26 PM
 
Check the $? variable after running the command.
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
     
hadocon  (op)
Mac Elite
Join Date: Oct 2001
Location: Internet
Status: Offline
Reply With Quote
Sep 9, 2002, 07:34 PM
 
Originally posted by Mactoid:
Check the $? variable after running the command.
I hope that this does not mak eme look like an idiot, but how would I go about doing that?

Thanx!
     
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Sep 9, 2002, 08:04 PM
 
% echo $?

or

% echo $status

[Edit]

By the way, an exit value of 1 doesn't always denote failure. Some programmers use 1 to denote a special exit case, an expected exit, possibly indicating that the program made changes; 0 would mean nothing changed, or no changes were encountered. 2 is an unexpected error, the sort that deserves a sudden exit, because an important procedure failed.
(Last edited by fitter; Sep 9, 2002 at 08:13 PM. )
     
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Sep 9, 2002, 08:14 PM
 
% echo $?

or

% echo $status
     
hadocon  (op)
Mac Elite
Join Date: Oct 2001
Location: Internet
Status: Offline
Reply With Quote
Sep 9, 2002, 09:20 PM
 
Originally posted by fitter:
% echo $?

or

% echo $status
So I enter this:

% echo $status ./main

and I get

2 ./main

I replaced my <return 1> with a <return 2> so it looks as though I am getting the right output.

have I done it right?

Thanx again gang!
     
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Sep 9, 2002, 10:09 PM
 
Originally posted by hadocon:


So I enter this:

% echo $status ./main

and I get

2 ./main

I replaced my <return 1> with a <return 2> so it looks as though I am getting the right output.

have I done it right?

Thanx again gang!
Though I have never done this, I would expect it to be:

% ./main ; echo $status

Then, main actually RUNS. It also runs right before you check the status.

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
hadocon  (op)
Mac Elite
Join Date: Oct 2001
Location: Internet
Status: Offline
Reply With Quote
Sep 10, 2002, 07:40 AM
 
Originally posted by Detrius:


Though I have never done this, I would expect it to be:

% ./main ; echo $status

Then, main actually RUNS. It also runs right before you check the status.

AWESOME! That works even better.

I now get

Goodbye, cruel world!
2

Thanx for all the great help gang, you rock!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:46 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2