[racket] putenv

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Tue Oct 23 04:00:03 EDT 2012

On 23 Oct 2012, at 08:46, heraklea at gmx.de wrote:

> Hmm, is there a Racket specific command to change env variables system wide??
> The (system "...") command also change it only locally….

No, and there can't be such a command, because the system itself doesn't support it (as before, my remarks and Jay's are specifically informed by unix, but  <http://en.wikipedia.org/wiki/Environment_variable> confirms the same model applies on Windows).

Any racket support for changing environment variables depends ultimately on underlying system support -- there is a system call which does the actual work.  The model of environment variables is (i) that they change the 'environment' in which processes are started, and (ii) that that environment is inherited when a process starts a subprocess.  Therefore there is no system call which can change a parent's environment, and so no function in Racket or any other language can do this.

The usual way around this on unix is to get a program to _print out_ a command which changes the environment, and have the parent execute this output:

% ./myprog
export VARIABLE=value
% eval `./myprog`
% echo $VARIABLE

There might be a similar mechanism available to you on Windows.

I hope this helps,


Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK

Posted on the users mailing list.