Thread overview | |||||
---|---|---|---|---|---|
|
June 25, 2014 Is their a way for a Child process to modify its Parent's environment? | ||||
---|---|---|---|---|
| ||||
I open a command line window, and run the following 6 line program void main() { string envPath = environment["PATH"]; writeln("PATH is: ", envPath); envPath ~= r";F:\dmd2\windows\bin"; environment["PATH"] = envPath; envPath = environment["PATH"]; writeln("PATH is: ", envPath); } It prints out the following PATH is: C:\Windows\system32;C:\Windows... PATH is: C:\Windows\system32;C:\Windows...F:\dmd2\windows\bin when the program exits, I'm back at the command line and I do a echo %PATH% which just shows C:\Windows\system32;C:\Windows... Anybody know of a way to make the change stick for the lifetime of the command window? |
June 25, 2014 Re: Is their a way for a Child process to modify its Parent's environment? | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | On 2014-06-25 03:53, WhatMeWorry wrote: > I open a command line window, and run the following 6 line program > > void main() > { > string envPath = environment["PATH"]; > > writeln("PATH is: ", envPath); > > envPath ~= r";F:\dmd2\windows\bin"; > > environment["PATH"] = envPath; > > envPath = environment["PATH"]; > > writeln("PATH is: ", envPath); > > } > > It prints out the following > > PATH is: C:\Windows\system32;C:\Windows... > PATH is: C:\Windows\system32;C:\Windows...F:\dmd2\windows\bin > > when the program exits, I'm back at the command line and I do a > > echo %PATH% > > which just shows C:\Windows\system32;C:\Windows... > > Anybody know of a way to make the change stick for the lifetime of the > command window? That's not possible. There is a workaround, DVM does something similar. Although, I don't remember how the code works for Windows but you can have a look at the code [1], or perhaps Nick can explain it. [1] https://github.com/jacob-carlborg/dvm/blob/master/dvm/commands/Use.d#L34 -- /Jacob Carlborg |
June 26, 2014 Re: Is their a way for a Child process to modify its Parent's environment? | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | On Tue, 24 Jun 2014 21:53:51 -0400, WhatMeWorry <kc_heaser@yahoo.com> wrote:
> I open a command line window, and run the following 6 line program
>
> void main()
> {
> string envPath = environment["PATH"];
>
> writeln("PATH is: ", envPath);
>
> envPath ~= r";F:\dmd2\windows\bin";
>
> environment["PATH"] = envPath;
>
> envPath = environment["PATH"];
>
> writeln("PATH is: ", envPath);
>
> }
>
> It prints out the following
>
> PATH is: C:\Windows\system32;C:\Windows...
> PATH is: C:\Windows\system32;C:\Windows...F:\dmd2\windows\bin
>
> when the program exits, I'm back at the command line and I do a
>
> echo %PATH%
>
> which just shows C:\Windows\system32;C:\Windows...
>
> Anybody know of a way to make the change stick for the lifetime of the
> command window?
Only the command shell can change it's own environment. When you execute commands that set an environment variable, those are shell builtins, not external programs.
You can run a batch file (which is not run in a separate process) which sets environment variables. This may be the only way to affect the environment. Basically, have a program run that dictates what to set, builds a batch file, then run that batch file from the command line. This could be done in another batch file.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation