public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Björn Stabel" <stabelweb@gmx.de>
To: cygwin@cygwin.com
Subject: Re: windows exit codes truncated to 1 Byte
Date: Thu, 31 Mar 2016 13:31:00 -0000	[thread overview]
Message-ID: <56FD268D.4060904@gmx.de> (raw)
In-Reply-To: <1233154500.205789.1459429282664.JavaMail.yahoo@mail.yahoo.com>

Am 31.03.2016 um 15:01 schrieb Cristian:
> I noted that exit codes returned by CMD and other apps (msiexec) are truncated to 1 byte (0 .. 255).
>
> Steps to reproduce:
>
> 1) Create a batch with this content:
> $ cat ./test.bat 
> @echo off 
> rem ==================== 
> echo Test exit code 266 
> exit /B 266 
> rem ==================== 
>
> 2) run the batch file:
> $ ./test.bat 
> Test exit code 266 
>
> 3) check exit code
> $ echo $? 
> 10 
>
>
> I would expect 266 but I got 10 instead. I checked for other codes and the result is the same. 
> Windows exit codes are represented using 32 bits, so is this limitation intentional?
POSIX specifies that the lower 8 bits of the exit status be made
available to the caller of wait/waitpid:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html

"WEXITSTATUS(stat_val) - If the value of WIFEXITED(stat_val) is
non-zero, this macro evaluates to the low-order 8 bits of the status
argument that the child process passed to _exit() or exit(), or the
value the child process returned from main()."

Maybe there's another way to get the entire status value, but this looks
like a POSIX limitation to me.
Cygwin is conformant here.

The more interesting problem is what happens if you do "exit /B 256" in
your batch.
In that case, bash would show a return status of zero.
That's what the WIFEXITED macro is used for. Not sure how you'd get that
from bash, though.

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


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

  reply	other threads:[~2016-03-31 13:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1233154500.205789.1459429282664.JavaMail.yahoo.ref@mail.yahoo.com>
2016-03-31 13:04 ` Cristian
2016-03-31 13:31   ` Björn Stabel [this message]
2016-03-31 15:24     ` Eric Blake
2016-03-31 18:50       ` Corinna Vinschen
2016-03-31 18:58         ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56FD268D.4060904@gmx.de \
    --to=stabelweb@gmx.de \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).