[Issue 18425] std.process environment["VAR"] = "NAME" does not always take effect
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 12 21:47:48 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18425
Rainer Schuetze <r.sagitario at gmx.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |r.sagitario at gmx.de
--- Comment #1 from Rainer Schuetze <r.sagitario at gmx.de> ---
Here's a simple test:
import std.process;
import core.stdc.stdlib;
import core.stdc.stdio;
extern(C) int putenv(const char*);
void main()
{
putenv("DFLAGS=1");
printf("1.DFLAGS=%s\n", getenv("DFLAGS"));
environment["DLAGS"] = "2";
printf("2.DFLAGS=%s\n", getenv("DFLAGS"));
system("echo 3.DFLAGS=%DFLAGS%");
}
It prints "1" three times.
The issue is that the C runtime caches the environment changes, but
std.process.environment bypasses the cache. Subsequent C runtime calls like
getenv, system or spawn use the cached environment.
--
More information about the Digitalmars-d-bugs
mailing list