> ...
> define rc integer
> run "unix_command" returning rc
let rc = rc / 256
^^^^^^^^^^^^^^^^^
> if rc != 0
> then
> display rc -- Often some different number than it "should" be
> else
> display rc -- Always 0
> end if
> ...
> the return value is often not what I expected. I can test against 0
> explicitly. Is this some type of integer size mismatch?
--
Hi Craig,
As you see above, you have to devide the returncode thru 256. This is
nowhere documented and I have found the solution by "try and error".
Hope that helps you,
Dirch
+----------------------------------------------------------------------------+
| Dirch Scheer email: sch...@stadt-mh.de |
| Amt 10-3 Tel. : +49 208 455 1006 |
| Stadtverwaltung (snail-)Mail : Ruhrstr. 32 |
| Muelheim an der Ruhr D-45468 Muelheim an der Ruhr |
|----------------------------------------------------------------------------|
| Inspiration gave them the motivation to move on out their isolation |
+----------------------------------------------------------------------------+
...
define rc integer
run "unix_command" returning rc
if rc != 0
then
display rc -- Often some different number than it "should" be
else
display rc -- Always 0
end if
...
the return value is often not what I expected. I can test against 0
explicitly. Is this some type of integer size mismatch?
Thanks,
Craig Ludington
cra...@craigl.pr.mcs.net
#---------------------- Informix Configuration -------------------#
# #
# Network: Twisted Pair Ethernet #
# Database space: character file #
# #
# Server (HP 715-75) uses: #
# ONLINE Engine 5.01 UD1 #
# I-STAR 5.01 UD1 #
# #
# Client (HP 715-50) uses: #
# I-4GL - 4.11 UC4 #
# RDS - 4.11 UC4 #
# ESQL/C - 5.01 - UD1 #
# I-NET - 5.01 - UD3 #
# I-4GL ID - 4.11 UC4 #
# I-SQL - 4.11 UC3 #
# #
#---------------------- Informix Configuration -------------------#
this subject was already handled a couple of times on net in the past.
I grep'ed in my archives and found at least two mails with useful ex-
planations (see below).
Your environment information (hardware config and exact versions of
Informix software) is also to recommend to all other people askig
questions via net: it helps in giving precise answers.
I hope the attached mail copies help you some.
Regards from Munich,
Peter (N) Advanced Support, Germany
-------------------------------------------------------------
->From uunet!rmy.emory.edu!ilist Thu Aug 4 23:59:32 MES 1994
->Subject: Ret value from RUN in 4GL
->Reply-To: uunet!MCS.COM!craigl (Craig Ludington)
->Organization: Craig Ludington, independent consultant
->To: uunet!rmy.emory.edu!informix-list
->X-Informix-List-To: infmx!infmuc!mu-infm...@uunet.uu.net
->X-Informix-List-Id: <news.8008>
...
define rc integer
...
Thanks,
Craig Ludington
cra...@craigl.pr.mcs.net
--------------------------------------------------------------------
>>From johnl Mon May 16 23:49:29 MES 1994
To: inform...@rmy.emory.edu, jpa...@hpbs3645.boi.hp.com
Subject: Re: return code wierdness (RUN...RETURNING)
Reply-To: uunet!informix.com!johnl (Jonathan Leffler)
Status: O
>From: Jack Parker <jpa...@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 (jo...@informix.com) #include <disclaimer.h>
--------------------------------------------------------------------------
>>From petern@infcee Mon Nov 29 23:22 MEZ 1993
To: petern@infcee
Subject: 4GL: RETURN (2 values)
For your information...
The RUN command in 4GL has an option to RETURN an integer type program
variable that will receivve the value returned by the program being
called. If the programmer uses exit() (in the 'child' process) to
pass a value back to the parent, the rsults received in is return_val
might be confusing.
The RUN command, issues the wiat() system call, which uses 16 bits
to hold status information.
The 4gl programmer gets 2 bytes from the wait() call;
The high byte (8 bits) contains the low byte from the child's exit
program statement (ie. if the child is passing a value back to
the parent); These bits can be accessed by return_val/256;
The low byte (8 bits) contains the termination status; it can be
accessed by return_val mod 256;
So, depending on the type of information the programmer is trying to
capture, he must use one or both of the access methods discussed
above.
AN EXAMPLE:
the child (shell script): testprog
rc=10
echo $rc
sleep 1
exit $rc
The parent process: test_run.4gl
main
define exit_status integer,
return_val integer,
hold_value integer
run "testprog" returning hold_value
let exit_status = hold_value mod 256
let return_val = hold_value /256
display "The program TESTPROG terminated with a status code of
",exit_status
display "TESTPROG returned the value of ", return_val, " to the 4GL
programmer"
end main
----------------------------------------------------------------------
----------------------------------------------------------------------
: ...
: define rc integer
: run "unix_command" returning rc
: if rc != 0
: then
: display rc -- Often some different number than it "should" be
: else
: display rc -- Always 0
: end if
this should probably meet your needs:
run "unix_command" returning rc
let rc = rc / 256
Unix returns the called program's exit status in the second byte of the
integer.