Re: Returning a value from .4gi
Posted in 1994
Chris (.Chris_Swecker@mac.avid.com) wrote: : I am trying to return an integer value from one .4gi to another ie; : RUN "progname.GO progname.4gi arg1" : The progname.4gi allows the user to select a record. : I would like to return a specific integer value back to the calling : program and use this integer value. : The two .4gi files reside in different directories. : My first thought was to use the following; : Calling program: : RUN "progname.GO progname.4gi arg1" RETURNING val : Called program: : EXIT PROGRAM(value) : Unfortunatly the returned integer value is not the value in the : EXIT PROGRAM(value) : I come to find out that this is just a status value. : Any Ideas besides using temp tables and unloading the value to a file? : Thanx Actually, the value returned by RUN ... RETURNING *is* related to the exit status of the subcommand. I ran this little test: main define i,j integer, cmd char(50) for i = 0 to 256 let cmd = "exit ", i using "<<<<" run cmd returning j display i, j end for end main Here is the abbreviated output: 0 0 1 256 2 512 3 768 4 1024 5 1280 6 1536 7 1792 8 2048 . . . . . . 254 65024 255 65280 256 0 From this test I empirically determined that 4GL always stores the exit status in the upper 8 bits of this return value. (Anybody know how or if the lower 8 bits are used?) Also, the return value looks like a 16-bit unsigned value since it wraps to zero at 65536. Unfortunately, this is very limiting because only 256 distinct exit codes can be detected, so in general a SMALLINT or INTEGER type cannot be returned this way. Your problem is a difficult one in general. I have solved it before by replacing the RUN statement with a C function which calls popen(). This allows the parent process to read the standard output of the child process, so that values can be returned from a DISPLAY statement: #--- child --- main define disp_val integer, exit_val smallint let disp_val = 500 let exit_val = 0 display x exit program (exit_val) end main #--- parent --- main define disp_val integer, exit_val smallint call run_popen("fglgo child_prog") returning disp_val, exit_val display disp_val # displays 500 display exit_val # displays 0 end main I don't have the source of run_popen() handy or I would list it here. This technique is also useful when character variables or multiple variable must be returned. If it weren't for this I probably would have resorted to using temp tables like you said. Hope this helps. -Jeff