Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authenticated-User: addump.covad.net Message-ID: <422F0DD7.1050904@zevelx.net> Date: Wed, 09 Mar 2005 09:53:11 -0500 From: zevel User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) MIME-Version: 1.0 To: Cygwin List Subject: Re: cygwin1.dll exit status References: <422C6575 DOT 2010006 AT zevelx DOT net> <6 DOT 2 DOT 0 DOT 14 DOT 0 DOT 20050307114035 DOT 034a9a18 AT pop DOT prospeed DOT net> In-Reply-To: <6.2.0.14.0.20050307114035.034a9a18@pop.prospeed.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > At 09:30 AM 3/7/2005, you wrote: > >>The latest version of cygwin1.dll ("cygwin1.dll" v0.0 ts=2005/3/1 11:01) does not return the correct exit status when a Cygwin application is called from Windows. Older versions such as ("cygwin1.dll" v0.0 ts=2004/11/10 8:34) do. >> >> >>Example: >> >>Create the bash script - error4.sh >>------------------------------------------------- >># >># simple script to return the exit status of 4 >># >>exit 4 >>------------------------------------------------- >> >>The from the Windows command prompt run the following: >> >>C:\TMP> bash error4.sh >>C:\TMP> echo %errorlevel% >> >>For an older cygwin1.dll the output is: >>4 >> >>For the newest cygwin1.dll the output is: >>1024 > > > > See . Also > look at the similar thread about this same issue last week: > . This is all > as-designed/as-intended. > > > > -- > Larry Hall http://www.rfk.com > RFK Partners, Inc. (508) 893-9779 - RFK Office > 838 Washington Street (508) 893-9889 - FAX > Holliston, MA 01746 > > Thank you that was exactly the problem. To "fix it" for returning an expected status to a Windows program I wrote a wrapper utility which calls a CYGWIN program and fixes the exit status. This program works with old and new CYGWIN and Non-CYGWIN programs. Two very big caveats: 1) build this utility with non-CYGWIN tools such as Visual C++, Borland or MinGW so its exit status is not broken. 2) the path of the executable must not contain any spaces. I hope this utility helps others. -Zevel ------------------------ File: FixStatus.cpp ------------------------- // // Utility to fix exit status from CYGWIN programs. // // If status passed on command line is greater than 255, // then use high byte as status // #include #include #include int main(int argc, char** argv) { bool bVerbose = false; int nStatus = 0; int ac = 1; char szCommand[4096] = {0}; int nIndex; while(ac < argc) { char* av = argv[ac++]; if(*av == '-') { // option switch(av[1]) { default: printf("Invalid option: %s\n", av); /*FALLTHROUGH*/ case '?': case 'h': printf("Usage: FixStatus [-h] command [arguments]\n"); exit(0); } } else { // first argument is executable - copy to command buffer nIndex = sprintf(szCommand, av); break; } } while(ac < argc) { // build up command line by quoting other arguments nIndex += sprintf(szCommand + nIndex, " \"%s\"", argv[ac++]); } nStatus = system(szCommand); if(nStatus >= 256) { // need to fix status from new CYGWIN nStatus >>= 8; } nStatus &= 0x00ff; exit(nStatus); return(0); // to quiet compiler } -- 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/