From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8377 invoked by alias); 31 Mar 2016 13:31:01 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 8358 invoked by uid 89); 31 Mar 2016 13:31:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=H*M:gmx, H*r:ip*192.168.0.5, cristian, Cristian X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.17.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 31 Mar 2016 13:30:50 +0000 Received: from [192.168.0.5] ([91.66.1.117]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0MdaiW-1aMPne2BLg-00PNbc for ; Thu, 31 Mar 2016 15:30:46 +0200 Subject: Re: windows exit codes truncated to 1 Byte To: cygwin@cygwin.com References: <1233154500.205789.1459429282664.JavaMail.yahoo.ref@mail.yahoo.com> <1233154500.205789.1459429282664.JavaMail.yahoo@mail.yahoo.com> From: =?UTF-8?Q?Bj=c3=b6rn_Stabel?= Message-ID: <56FD268D.4060904@gmx.de> Date: Thu, 31 Mar 2016 13:31:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <1233154500.205789.1459429282664.JavaMail.yahoo@mail.yahoo.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-UI-Out-Filterresults: notjunk:1;V01:K0:3BbnMZbZP94=:tRvbdQsE7LCcfoac6DBAM2 vnujV0r1FT6LteHXjtXqp8cRVuDQejL30PQ6Cn1Nff+Ft7wQFwmxT20/oGMYR+68gGQHoNl91 7o0V4xIa6HHZJtDg4bgOhThirXQjt6Bzgs8stYS6RkvkTHN42anAE8zBdlslA+yetyLLeDEss fsTbL1HbcYJulaG67SH3ywTDMgCs07g+wRGqTUiu1UBlly7GMawcbMbQx8SVSC2zuz8aOKfpD +kXrJuidqTd67ar9JXaYuoIMJWJGgDQUa7agbBfrbBkJll79aVw/LSCHNUHFrznIH88K+oS0A 3IV8t3tu7cOdKXpoI0Ou8TnDfyaJp3TPkFa63V7HgT9UISgY5M/vAZG+jyyj8S0BiSX8ubrAg 8TH1qgmj9bwWyGph2d+CH4sSlj9G08LceX76uOx++gaAUTEmPCkg2uofGHK0yLANvNVXDVJHD jBZPdyH+cUn4xFo1lIh0QvGc8BheOv0G0DDpVC0UCbtgkdIGCIucIOO3JIoUrbeaI/cuXdeZG 7r21Tw02XIghyo3d+OXndwBfDgfYQMItaeKlYQceILagLK9dZWO/mpj1KAxkI59zX8ihM9q4e iZ/0Io7fdCgNSOq33n+OcTXaBhVuylO92/PNGKNj3TIWSqPbMkbJgldLpMcyBcXk1MSZS8eDb dcZbbN0wu+hzzxZzSRocPSUK0kR6zpF5HbQgBffA+bdVH2AftRdV6WM7GTCA+T62C+PbDaNJW H9osiwv5jBjNgyrU8ynm+X7jnzBgq9ScTqovUGEpwYvECmel0tfPA1WcUFiaKj6Fk4H+1aws7 peGKNik X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg00572.txt.bz2 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