Re: Changing the ENV
Posted in 1995
rob@dssmktg.com (Robert Minter) writes: > For all who are curious, how do you alter the environment while running > a 4gl program? I've tried this: > > MAIN > DEFINE arg_str CHAR(20) > LET arg_str = fgl_getenv("ROBS_ENV") > DISPLAY "arg_str = ", arg_str CLIPPED > RUN "ROBS_ENV=hello ; export ROBS_ENV" > LET arg_str = fgl_getenv("ROBS_ENV") > DISPLAY "arg_str = ", arg_str CLIPPED > END MAIN > > and both displays are blank. Any clues? Sure. It has to do with the way unix spawns new shells. Imagine the "RUN" command creating a bubble on the side of your current environment, and having all the same attibutes. Then you move into that bubble and start working. Here is where you export "ROBS_ENV" and the changes occur. When the "RUN" command is completed, the bubble collapses and you return to your original environment. You can't moify your current environmnet with a 4gl without some convuluted "C" work, but you can try this: MAIN DEFINE cmd char(255) let cmd = "a=1,b=2,c=3,d=4,e=5;export a b c d e;cd some_dir;some_prog" run cmd END MAIN Then some_prog will work with the ENV variables you pass on the command line. __ _ _ __ _ >> | \\ __ ___ ___ __| | / _| __| |_ _ _ ___ _ _ __ ___ << | | / _' \\ ' | / _' | \\_ \\/ _| ' \\| '_/ _ \\ ' \\/ _/ -_) C|~~| |__/\\__,_|\\_/|_\\__,_| |__/\\__|_||_|_| \\___/_||_\\__\\___| `--'