0

I write a program which is run under the terminal on windows, it needs to specify the PATH so that it could be called without full absolute path. However, I have specified the "PATH" and save the value to the "users'" environment variables. However, this doesn't take effect unless I reboot the terminal. If I manually set the PATH like this:

PATH=%PATH%;D:\folder

The terminal could find the executable program under the D:\folder, if I call the set in an external program, it seems it doesn't affect current terminal.(Maybe the external program is the child progress of current terminal which the PATH only exists for current session). I already tried "set PATH=xxx" and "PATH=xxx", none works. So the problem is how can I reset current terminal session's envionment by an external program? I don't want to manually set the PATH in the terminal, this would be tedious for the user. Is there a way to do so? BTW, I noticed this Setting Windows PowerShell path variable, after I called "setx PATH D:\folder -m", it shows that the operation was success, but I output the $PATH and the value doesn't include D:\folder

Community
  • 1
  • 1
python
  • 1,662
  • 2
  • 20
  • 34
  • possible duplicate of [Reload the path in powershell](http://stackoverflow.com/questions/17794507/reload-the-path-in-powershell) – Ansgar Wiechers Sep 26 '14 at 13:31

2 Answers2

0

Look at this link: http://technet.microsoft.com/de-ch/magazine/2008.10.windowspowershell.aspx
Maybe you can setup this profile and do the PATH=%PATH%;D:\folder there. The profile is loading every time you start powershell.exe.

Patrick
  • 1,400
  • 8
  • 15
  • Thanks, Patrick, but I didn't get it work. After install my program in the terminal (this will copy the dependent files to the D:\folder), I already set the PATH to the registry and if I launch a new terminal, the program could be launched without a full path. But I wish it could take effect immediately without restart the terminal. – python Sep 26 '14 at 09:37
0

To answer the exact question you've asked, no, there is no way for an invoked program to alter the callers environment. If there was, I'd imagine there would be all kinds of crazy ways to turn that into a security nightmare.

The calling program could decide it explicitly wants to get values from the called process.

There is a slightly hacky (but effective) way of doing this using this script: http://poshcode.org/2176

Alternatively, @Ansgar linked to another possibility.

Jason Shirk
  • 6,874
  • 19
  • 28