digitalmars.D.learn - How to modify process environment variables
- Ky-Anh Huynh (12/12) Oct 16 2017 Hi,
- ketmar (5/15) Oct 16 2017 you can use libc's `putenv()` in D too, it is ok. just import
- Ky-Anh Huynh (2/7) Oct 16 2017 I see :) I have always tried to avoid C if possible :D
- Rene Zwanenburg (3/11) Oct 17 2017 As an alternative, a search on code.dlang.org turned up this lib:
- Ky-Anh Huynh (4/17) Oct 17 2017 Awesome. I will take a look definitely. I have a similar way in
- Jacob Carlborg (5/20) Oct 17 2017 Use std.process.environment [1] and assign to it like an associative arr...
- Ky-Anh Huynh (9/32) Oct 17 2017 Oh thanks a lot for your pointing out, Jacob. That's the thing
Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive: http://man7.org/linux/man-pages/man3/putenv.3.html (FIXME) I come to this question as I want to set some custom variables for my unittests. My program reads some tokens from system environments, and it's convenient if I can simulate different cases for testings. Thanks for your reading and support.
Oct 16 2017
Ky-Anh Huynh wrote:Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive: http://man7.org/linux/man-pages/man3/putenv.3.html (FIXME) I come to this question as I want to set some custom variables for my unittests. My program reads some tokens from system environments, and it's convenient if I can simulate different cases for testings. Thanks for your reading and support.you can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there. D is not antagonistic to C, and doesn't try to replace the whole libc with it's own libraries. so if you see something that libc has and you'd like to use -- just do it! ;-)
Oct 16 2017
On Tuesday, 17 October 2017 at 04:56:23 UTC, ketmar wrote:you can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there. D is not antagonistic to C, and doesn't try to replace the whole libc with it's own libraries. so if you see something that libc has and you'd like to use -- just do it! ;-)I see :) I have always tried to avoid C if possible :D
Oct 16 2017
On Tuesday, 17 October 2017 at 05:57:50 UTC, Ky-Anh Huynh wrote:On Tuesday, 17 October 2017 at 04:56:23 UTC, ketmar wrote:As an alternative, a search on code.dlang.org turned up this lib: http://code.dlang.org/packages/dotenvyou can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there. D is not antagonistic to C, and doesn't try to replace the whole libc with it's own libraries. so if you see something that libc has and you'd like to use -- just do it! ;-)I see :) I have always tried to avoid C if possible :D
Oct 17 2017
On Tuesday, 17 October 2017 at 08:42:09 UTC, Rene Zwanenburg wrote:On Tuesday, 17 October 2017 at 05:57:50 UTC, Ky-Anh Huynh wrote:Awesome. I will take a look definitely. I have a similar way in my NodeJS team :DOn Tuesday, 17 October 2017 at 04:56:23 UTC, ketmar wrote:As an alternative, a search on code.dlang.org turned up this lib: http://code.dlang.org/packages/dotenvyou can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there. D is not antagonistic to C, and doesn't try to replace the whole libc with it's own libraries. so if you see something that libc has and you'd like to use -- just do it! ;-)I see :) I have always tried to avoid C if possible :D
Oct 17 2017
On 2017-10-17 06:51, Ky-Anh Huynh wrote:Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive: http://man7.org/linux/man-pages/man3/putenv.3.html (FIXME) I come to this question as I want to set some custom variables for my unittests. My program reads some tokens from system environments, and it's convenient if I can simulate different cases for testings. Thanks for your reading and support.Use std.process.environment [1] and assign to it like an associative array. [1] https://dlang.org/phobos/std_process.html#.environment.opIndexAssign -- /Jacob Carlborg
Oct 17 2017
On Tuesday, 17 October 2017 at 11:49:32 UTC, Jacob Carlborg wrote:On 2017-10-17 06:51, Ky-Anh Huynh wrote:Oh thanks a lot for your pointing out, Jacob. That's the thing I'm looking for. The C version is not so bad though ``` import core.sys.posix.stdlib; import std.string: toStringz; string jenkinsToken = "TEST_TOKEN="; putenv(cast(char*)jenkinsToken); ```Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive: http://man7.org/linux/man-pages/man3/putenv.3.html (FIXME) I come to this question as I want to set some custom variables for my unittests. My program reads some tokens from system environments, and it's convenient if I can simulate different cases for testings. Thanks for your reading and support.Use std.process.environment [1] and assign to it like an associative array. [1] https://dlang.org/phobos/std_process.html#.environment.opIndexAssign
Oct 17 2017