www.digitalmars.com         C & C++   DMDScript  

D - environment variable

reply manfred toppoint.de writes:
Hello,

how can i get the environment variable's in D.

In c i can do this: 

int main(int argc, char* argv[],char* envp[]) {
int i = 0;
while (envp[i]!=NULL) {
printf("\n");
printf(envp[i++]);
}
return 0;
}
Sep 02 2003
parent reply "Charles Sanders" <sanders-consulting comcast.net> writes:
If this is windows, you can use DIG's

Control.OS.environmentalVariable(char [] name)

http://www.opend.org/dig/classControl_1_1OS.html

But only if you know the env variable name.

Charles

<manfred toppoint.de> wrote in message
news:bj27g4$28a4$1 digitaldaemon.com...
 Hello,

 how can i get the environment variable's in D.

 In c i can do this:

 int main(int argc, char* argv[],char* envp[]) {
 int i = 0;
 while (envp[i]!=NULL) {
 printf("\n");
 printf(envp[i++]);
 }
 return 0;
 }
Sep 02 2003
parent Helmut Leitner <helmut.leitner chello.at> writes:
Charles Sanders wrote:
 
 If this is windows, you can use DIG's
 
 Control.OS.environmentalVariable(char [] name)
 
 http://www.opend.org/dig/classControl_1_1OS.html
 
 But only if you know the env variable name.
 
 Charles
 
 <manfred toppoint.de> wrote in message
 news:bj27g4$28a4$1 digitaldaemon.com...
 Hello,

 how can i get the environment variable's in D.

 In c i can do this:

 int main(int argc, char* argv[],char* envp[]) {
 int i = 0;
 while (envp[i]!=NULL) {
 printf("\n");
 printf(envp[i++]);
 }
 return 0;
 }
It seems that Burton has only put a thin wrapping over standard Phobos functions: /* from stdlib.d */ extern (C) char *getenv(char *varname); extern (C) int putenv(char *envstring); /* from net\BurtonRadons\dig\windows\windows.d */ /** Return an environment variable or null if this is not assigned. */ static char [] environmentVariable (char [] name) { return string.toString (getenv (toStringz (name))).dup; } /** Assign an environment variable. */ static void environmentVariable (char [] name, char [] value) { putenv (toStringz (name ~ "=" ~ value)); } -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Sep 02 2003