Bug 10580 – spawnShell/pipeShell changes some environment variables (incl. PATH)

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-08T22:51:00Z
Last change time
2017-07-05T15:50:48Z
Assigned to
bugzilla
Creator
thelastmammoth

Comments

Comment #0 by thelastmammoth — 2013-07-08T22:51:17Z
----main.d: import std.process; import std.stdio; void main(){ writeln(environment["PATH"]); system("echo $PATH"); spawnShell("echo $PATH").wait; spawnShell("echo $0").wait; } ---- (on OSX if that matters, and I've set my shell to zsh but this isn't the problem) export PATH=/usr/bin path/to/dmd -run path/to/main.d #this prints: /usr/bin /usr/bin /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:... (+ other stuff) /go/bin /bin/zsh The bug is that spawnShell("echo $PATH") should IMO return the same as system("echo $PATH").
Comment #1 by thelastmammoth — 2013-07-08T23:41:59Z
it also changes these (at least on OSX): MANPATH SHLVL ( this one is normal though)
Comment #2 by thelastmammoth — 2013-07-08T23:43:37Z
furthermore the output of command env is returned in a different order
Comment #3 by bugzilla — 2013-07-28T07:54:24Z
I cannot reproduce this on Linux, so it's hard to say what the issue is. It would be great if someone else could try this on OSX. spawnShell() does not touch the environment unless explicitly requested, so I think the answer lies somewhere else. It looks almost like spawnShell() starts the shell as a login shell. In that case it would read various startup scripts, and re-set PATH along with some other environment variables. Could you please run the following commands in a terminal? export PATH=/usr/bin $SHELL -c 'echo $PATH' $SHELL -l -c 'echo $PATH' (Note the single quotes, which delay expansion of the PATH variable.)
Comment #4 by timothee.cour2 — 2014-09-15T07:31:45Z
export PATH=/usr/bin $SHELL -c 'echo $PATH' =>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:... (+ other stuff) $SHELL -l -c 'echo $PATH' => /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:... (+ other stuff) ie, spawnShell("echo $PATH").wait; returns same as $SHELL -c 'echo $PATH' and $SHELL -l -c 'echo $PATH'
Comment #5 by timothee.cour2 — 2014-09-15T07:44:50Z
The problem persists even when explicitly providing the 'const string[string] env' variable.
Comment #6 by dlang-bugzilla — 2017-07-05T15:50:48Z
I believe this was fixed by https://github.com/dlang/phobos/pull/3051. *** This issue has been marked as a duplicate of issue 14282 ***