'python change powershell curren session env variable

What I want is:

  1. opened a powershell command line
  2. run a "script.py" file. So that add a $env:aa=bb env variable.
  3. I run $env:aa in current powershell command line. Can print bb rightly.

More specific.

I have a script that let user select the java home in the prompt list, and set the JAVA_HOME variable(in system widely). It worked after user reopen the powershell. But I want insert the $JAVA_HOME/bin in front of the $env:path in current session. So the choice can effect immediately.

How the script.py like?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source