"Sourcing" a script's env into D?

Steven Schveighoffer schveiguy at yahoo.com
Thu Sep 29 14:20:44 PDT 2011


On Thu, 29 Sep 2011 17:02:28 -0400, Nick Sabalausky <a at a.a> wrote:

> "Graham Fawcett" <fawcett at uwindsor.ca> wrote in message
> news:j62ido$1n0s$1 at digitalmars.com...
>> On Thu, 29 Sep 2011 13:31:13 -0400, Nick Sabalausky wrote:
>>
>>> Due to process separation, the following won't work:
>>>
>>> script.sh:
>>> #!/bin/sh
>>> SOME_VAR=foobar
>>>
>>> test.d:
>>> import std.process;
>>> void main()
>>> {
>>>     system("./script.sh");
>>>     assert(environment["SOME_VAR"] == "foobar");
>>> }
>>>
>>> This, of course, is because the script is run in a totally separate
>>> process (AIUI). The same thing happens in Windows, too.
>>>
>>> Is there some way to actually get the env that results from the script?
>>> I'm looking for solutions for both Posix and Windows.
>>
>> What about "export SOME_VAR=foobar"?
>>
>
> Still doesn't work.

This only passes the environment to children started after the export is  
done.  A child process cannot affect a parent process' environment  
directly.  Nor can a parent affect an already-running child.

-Steve


More information about the Digitalmars-d-learn mailing list