[GRASS-dev] trying to set environment vars from a C program
Glynn Clements
glynn at gclements.plus.com
Sun Dec 17 11:55:02 EST 2006
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.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list