delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/03/02/17:07:33

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <42263A07.3DE4DBF9@dessent.net>
Date: Wed, 02 Mar 2005 14:11:19 -0800
From: Brian Dessent <brian AT dessent DOT net>
Organization: My own little world...
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: More error level issues
References: <001d01c51f66$9de4ccf0$05010e0a AT 2mbit DOT com> <20050302204530 DOT GA25089 AT trixie DOT casa DOT cgf DOT cx> <004701c51f6a$93aba020$05010e0a AT 2mbit DOT com>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com

Brian Bruns wrote:

> Yeah, I know of that post.  I'm still _highly_ confused as to this -
> chalk it up to the fact I'm more used to dealing with return codes in
> Linux, so forgive my ignorance.  I'm also not the greatest programmer
> in the world.
> 
> Your telling me an exit code of 1 inside of cygwin (and Linux for that
> matter) is supposed to be considered as errorlevel 256 by Windows
> rather then 1?  I'm sorry if I am not catching on here entirely of why
> this is.

Under unix, the "process completion status" is an integer, and is the
value returned by the wait() family of functions.

Bits 0(LSB) through 7 of this integer convey information about how the
process was stopped.  Bits 8 though 15 contains the exit value that the
program supplied to exit() or to its main() function.

If the value of bits 0 through 6 is zero then it means the program
terminated normally, and the exit status is in bits 8-15.

If bits 0 through 6 are all set then the process was stopped, and the
value of the signal that caused the stop is in the exit value field.

If bits 0 through 6 are not all zeros or not all ones then the process
was terminated by a signal, and the value of the signal is the value in
those bits.

Bit 7 signifies whether a core dump was produced.

Anyway, what cgf is saying is that under linux if you call wait() on a
process that "returns 1", i.e. calls exit(1), the process completion
status will be 256.  Your shell handles interpretating the completion
status so that it knows how the process ended, and sets $? to the
"return value".

(The SUSv3 defines all this in terms of macros in sys/wait.h to check
the process completion status, so the actual bits are probably not an
actual standard but certainly a de-facto one.)

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019