Changing Environment Paths using D language's Phobos Library
BoQsc
vaidas.boqsc at gmail.com
Sat Jun 29 09:28:03 UTC 2019
I would like to remove/add/change Environment Paths using D
language's Phobos.
https://en.wikipedia.org/wiki/PATH_(variable)
I saw in the documentation that there is a class file
"std.process : environment" that has the supposed ability to
minipulate environment variables.
https://dlang.org/library/std/process/environment.html
I couldn't find a good documentation on how to search and replace
strings using Phobos Library. However it seems that it might be
possbile by importing "std.array : replace" function.
https://forum.dlang.org/post/jnua50$1e4a$1@digitalmars.com
https://dlang.org/library/std/array/replace.html
So, here we are, testing if it is possible to retrieve and set
the Environmental Variables.
> import std.stdio : writeln;
> import std.array : replace;
> import std.process : environment;
>
>void main(){
>
>
> // Retrieve environment variable "path" for testing if it is
>possible
> // to retrieve it by using D language Phobos Library
> auto environmentPaths = environment.get("path");
> writeln(environmentPaths); // Works as expected: we can see the
>output of Paths.
>
> // Create a new Environement variable for testing if it is
>possible
> // to Create it with D language Phobos Library
> environment.opIndexAssign("variableName", "Some Random Value
>Here");
> auto environmentalVariable = environment.get("variableName");
> writeln(environmentalVariable); //Unexpected: absolutely no
>output.
Alright, now that we see it is possible to retrieve environmental
variable, that's great.
However, setting the variable via "environment.opIndexAssign"
seems to not work.
What should we do?
I don't know.
More information about the Digitalmars-d-learn
mailing list