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.

Reply via email to