[GRASS-dev] trying to set environment vars from a C program

Benjamin Ducke benjamin.ducke at ufg.uni-kiel.de
Mon Dec 18 02:44:23 EST 2006


Well, I never stop learning new things with GRASS ...
Right, I should have just looked into the GRASS API, it's
always amazing to see how many things are already covered
in there.
Florian pointed out G_getenv/G_setenv to me and that -- of
course -- works nicely.

Thanks, everybody.


Glynn Clements wrote:
> Benjamin Ducke wrote:
> 
>> I am working on a set of modules to integrate GRASS with R.
>> For this I need to read and set some global variables for R scripts to
>> use.
>> I would like to use shell environment variables for this and
>> set them through a C module.
>> However, if I use the C function setenv() in program foo.c, it seems to
>> only add variables to the environment of foo.c.
>> When foo.c terminates, all variables set with senenv() will be gone.
>>
>> I have not found a way to modify the environment of the shell that
>> starts foo.c so that the new variables will be available in the calling
>> shell after foo.c has exited.
>>
>> Is this somehow possible
> 
> No. One process cannot modify the environment of another process
> (other than by directly modifying that process' address space, which
> isn't really a viable option).
> 
> That's why export (sh) and setenv (csh) are shell built-in functions;
> a separate program wouldn't work.
> 
>> or will I have to fall back to storing variables and values in an
>> ASCII file?
> 
> That's why GRASS has $GISRC for "GRASS variables", i.e. so that you
> can have programs which record information for subsequent use by other
> programs.
> 

-- 
Benjamin Ducke, M.A.
Archäoinformatik
(Archaeoinformation Science)
Institut für Ur- und Frühgeschichte
(Inst. of Prehistoric and Historic Archaeology)
Christian-Albrechts-Universität zu Kiel
Johanna-Mestorf-Straße 2-6
D 24098 Kiel
Germany

Tel.: ++49 (0)431 880-3378 / -3379
Fax : ++49 (0)431 880-7300
www.uni-kiel.de/ufg




More information about the grass-dev mailing list