Re: 4GL RUN command question
Posted in 1998
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL, Server Administration, Third-Party Tools & Monitoring
Another way may be:
1) To have a passing values table (not temporary)
CREATE TABLE passing ( pid INTEGER, proc_value INTEGER);
2) Define a shell environment variable
PROC_PID=$$
export PROC_PID
3) Run the 4gl caller program
(inside the 4gl...)
DELETE FROM passing WHERE pid = fgl_getenv("PROC_PID")
RUN my_command_string
SELECT proc_value INTO my_local_int_var_ret_by_child
FROM passing
WHERE pid = fgl_getenv("PROC_PID")4) In the child shell script:
#!/bin/shell
RET_VAL=`program_that_returns_int_value`
dbaccess my_database - - <<EOF
INSERT INTO passing VALUES(${PROC_PID}, ${RET_VAL}); EOF
exit
I have used personally this mechanism successfully. (A "C" program that
makes parsing and special calculations and returns a FLOAT value).
Byte byte!
--
Mario R. Canto
mcanto@intec.unl.edu.ar
mcanto@intec.arcride.edu.ar
http://www.intec.unl.edu.ar/~mcanto
Peter Lancashire wrote:
>
> Candy McCall wrote:
>
> Billy Wheeler asked for someone more awake. Here goes... ZZZzzzz...
>
> >
> > Within a 4GL program, I want to run a shell
> > script which will calculate an integer value.
> > I then want to read that integer value into
> > the 4GL program. Is it possible to
> > read that value using the "RUN shell_script RETURNING
> > integer_variable" command?
>
> The shell will return its status to 4GL (see manual). It does this with
> the parameter to the exit command. As Billy says, it can be 0 to 255,
> with 0 by convention meaning OK and the rest an error in the shell
> script.
>
> >
> > I've also thought of setting a value in a shell
> > environment variable in the shell script and
> > then reading the value using fgl_getenv(), but since
> > the shell_script is a child process, I didn't think I could
> > set a shell environment variable of the parent process
> > (the 4GL program).
>
> Correct. A moment's thought will reveal the awful security risk if you
> could do this.
>
> >
> > A third way I've thought of is to place the integer variable
> > in an ASCII file, then using the LOAD command, load
> > the value into a temporary table. This is not the most
> > elegant way of getting that value, but it will work.
> > Does anyway know of a better way?
>
> Not elegant and not quick, as you will need two database connections.
>
> You could write to a file in the shell and then read (or load) that from
> the 4GL caller - only one connection. There are file-reading functions
> in the IIUG archives.
>
> >
> > Thanks in advance,
> > Candy
> > --
> > Candy McCall
> > ONLINE Computing, Inc.
> > (candym@olcinc.com)
>
> Returning to the beginning, why do you want to do this? Calling a shell
> script from 4GL just to do some sums seems strange. Is there some other
> way?
>
> If you want a general expression evaluation, there has been some
> discussion of that recently - see the usual dejanews. It occurs to me
> that you could embed a tcl interpreter into your 4GL program. Don't ask
> me how it's done, I just have a feeling that's what tcl was designed
> for. Anyone else know more than I do (silly question)?
>
> --
> Peter Lancashire
> Information Systems Specialist, Bayer plc
> Eastern Way, Bury St Edmunds, Suffolk, IP32 7AH, UK
> Tel: +44-1635-562258, Fax: +44-1635-562281
> ---
> If all else fails, read the instructions and the release notes.
> Join Infuse, the UK Informix User Group at http://www.infuse.org.uk/
> -