Re: return code wierdness
Posted in 1994
>From: Jack Parker <jparker@hpbs3645.boi.hp.com> >Subject: return code wierdness >Date: Fri, 13 May 94 15:01:58 MDT >X-Informix-List-Id: <list.3953> > >Could one of you informix blokes explain this? > >1) > >From 4gl: > RUN command RETURNING retcode > > # Command exits with a return code of 4 > > DISPLAY retcode # displayed value is 256*4 - or 1024 > >2) > >From 4gl: > exit program 3 > > OS says return code is 3 > >3) >From 4gl: > exit program -3 > > OS says return code is 253 (256 + return code) From the 6.0 Tools Release Notes (which expresses it somewhat more accurately than the 4.12 Release Notes): TOOLREL_6.0 Page 44 STATUS VALUE FROM "RUN ... RETURNING" ===================================== The behavior of the value returned from a 4GL "RUN ... RETURNING" clause was different on different machines. Because of OS limitations (see exit(2) or wait(2) in the Unix Programmer's Manual), a range of only 256 values can be returned by the exit status of a command. However, the operating system uses the low order 8 bits of a 16-bit integer for its own information, and the 256 exit status values are stored in the high order 8 bits of the 16-bit integer. When this 16-bit value is stored in a 4GL INTEGER variable, it is always treated as an unsigned quantity, whereas previously it could be treated as either signed or unsigned depending on platform. If the status is stored in a SMALLINT, any exit status between 128 and 255 (and an exit status of -1 is equivalent to 255) is stored as a negative number. For portability, always store the status of the command in an INTEGER. You need to divide the value saved by 256 to get the actual exit status. The low order bits are only non-zero if the shell which ran the command was killed by an unexpected signal. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>