[racket] setting environment with subprocess?

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Apr 30 18:06:07 EDT 2012

Just now, Berthold Baeuml wrote:
> Hi,
> 
> when starting a new process from racket (e.g., using subprocess) is
> there a way to set the environment for the new process, like C-libs
> execve allows? Maybe, a keyword argument could be added to
> subprocess?

A better solution IMO is how Emacs deals with environment variables --
translated to racket, this would be a new parameter, say
`current-subprocess-environment', which you would manipulate as usual,
for example:

  (parameterize ([current-subprocess-environment
                  (cons (cons "FOO" "whatever")
                        (current-subprocess-environment))])
    ...anything with subprocesses here...)

And you'd also get the usual tricks, like allowing arbitrary
environment manipulation:

  (parameterize ([current-subprocess-environment
                  (current-subprocess-environment)])
    (putenv "FOO" "whatever")
    ...)

or starting a process in a clean environment to avoid leaking
environment values (a problem that comes up with rudybot):

  (parameterize ([current-subprocess-environment '()])
    (putenv "FOO" "whatever")
    ...)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.