Re: Env variables in 4GL
Posted in 1993
->From: gau@mendel.sing.ingr.com (Gau Lai Choon) ->Subject: Env variables in 4GL ->To: informix-list@rmy.emory.edu ->Date: Wed, 27 Oct 93 10:10:08 SIN ->Cc: informix-distr2@timtow.b1.ingr.com -> -> Hi wise people, -> -> How do I include an environmental variable in 4GL ? -> -> eq. -> -> $export APP_DIR=/usr3/mis/lis/utility (at system level) -> -> GLOBALS "$APP_DIR/globals.4gl" (to include the path APP_DIR) in the 4gl code. -> -> ^ -> | -> -> this will give an error during compilation... -> -> All input welcomed !!! -> Thanks in advanced. -> -> Best Regards -> -> Gau Lai Choon -> Application Engineer -> Intergraph Singapore -> -------------------- -> gau@mendel.sing.ingr.com The information below will help you access environment variables at program run time. Unfortunately, this will not solve your compile time problem with the GLOBALS statement. I always found that I needed to copy the globals file into any directory in which I planned to compile, and then use the statement: GLOBALS "globals.4gl" To access environment variables at *run* time, 4GL vers. 4.10 and newer have the function fgl_getenv(). It is documented in the 4.10 4GL Supplement. I don't have later versions, so I can't give you the reference. For you netters who are running earlier versions of 4GL, I offer the following: /* Created by: Bill Gammill, 01/09/90 * Modified by: Alan Popiel, 05/21/90 * * i_getenv() Performs call to UNIX system call: getenv(). * Reads UNIX environmental variable specifed and passes back to * Informix per Informix calling specs. * * syntax: * CALL i_getenv(env,len) RETURNING envvar * LET envvar = i_getenv(env,len) * * CALL arguments: * env -- null terminated string naming a UNIX environmental variable. * Limited to 20 characters. * len -- integer number of character in string, EXcluding NULL. * * RETURNING arguments: * char envvar -- null terminated string. * -- null string returned on error. */ int i_getenv(nargs) int nargs; { char *envvar; /* Pointer to env string to be obtained. */ int len; /* Input from stack: Length of env var string. */ char name[21]; /* Input from stack: Env var to try and obtain. */ /* Insure correct number of arguments have been pushed on the stack. */ if (nargs != 2) { retquote(""); /* Failure flag. */ return(1); /* Number of arguments returned. */ } /* Pop calling arguments from the stack. */ popint(&len); len++; popquote(name,len); /* Read UNIX environmental variable. */ if(!(envvar = (char *)getenv(name))) { retquote(""); /* Failure flag. */ return(1); /* Number of arguments returned. */ } /* Push return arguments to the stack. */ retquote(envvar); /* Value of environment variable. */ return(1); /* Number of arguments returned. */ } Regards, Alan ___________________________ ______________________| R. Alan Popiel |__________________________ \\ Internet: | Martin Marietta, Tech Ops | / \\ alan@den.mmc.com | P.O. Box 179, M/S 5422 | Std disclaimers apply. / )Voice: | Denver, CO 80201-0179 USA | ( / 303-977-9998 |___________________________| (But you knew that!) \\ /________________________) (____________________________\\