"Sourcing" a script's env into D?

Regan Heath regan at netmail.co.nz
Fri Sep 30 02:56:29 PDT 2011


On Fri, 30 Sep 2011 07:18:34 +0100, Jacob Carlborg <doob at me.com> wrote:

> On 2011-09-29 19:31, 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.
>
> Either you do it how it works in DVM or have the script write out a file  
> that the parent process reads.

On windows you can use:

set>file.txt

this will output the whole environment into file.txt in the form:

label=value

So, add that line to the end of script.cmd|bat|sh and then have the D  
program read it .. using std.getopt perhaps?

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list