Re: Set an environment variable from within a 4GL program?
Posted in 1995
I wrote: >>Maybe, but if you're planning on setting any environment variables that >>Informix uses, I'm pretty sure Informix reads them when you start up your >>application, so anything you change in the application will never be read. James Fischer <jfischer@inimnd.com> wrote: > The above paragraph is both misleading and 100% WRONG. > > Setting or changing any environment variable will work just fine, > 100% of the time. <lots of stuff deleted for brevity> > E-mail me if you want source. I'd like source. (Oops, I was supposed to e-mail, wasn't I?) I may be wrong (it wouldn't be the first time), but if James Fischer is right, he must be doing something I don't know about. I did the following: (with my compliments to David A. Snyder, from whom I took the dbputenv source) --------------- Test Code --------------- main define envvar char(20) define mval money (10,2) let mval = 199.99 let envvar = fgl_getenv ("DBMONEY") display "mval = ", mval, ", DBMONEY = ", envvar let envvar = "DBMONEY=,FF" call dbputenv (envvar) let envvar = fgl_getenv ("DBMONEY") display "mval = ", mval, ", DBMONEY = ", envvar end main ------------------------- #include <ctype.h> #include <string.h> dbputenv(arg) int arg; { static char s[513]; popquote(s, sizeof(s)); rtrim(s); retint(putenv(s)); return(1); } rtrim(s) char *s; { int i; for (i = strlen(s) - 1; i >= 0; i--) if (!isgraph(s[i]) || !isascii(s[i])) s[i] = '\\0'; else break; } ---------------------------------------- I got the following output: mval = $199.99, DBMONEY = mval = $199.99, DBMONEY = ,FF Just for grins, I then set my DBMONEY to ,SK: mval = 199,99SK, DBMONEY = ,SK mval = 199,99SK, DBMONEY = ,FF If there's some other way to change the environment variables that I don't know about, or there's something wrong with my program, I'd like to know. If not, well, statements containing the phrase "100%" are just so risky, don't you think? June ---- June Tong Informix Asia/Pacific ---- ---- On-Loan Engineer Singapore ---- ---- junet@informix.com (65) 298-1716 ----