stting environment variables in powershell by calling python script that prints $env:myVar=myvalue
- by leeg
I have some legacy python scripts that manage my shell environment for all the programs and plugins I am running on Linux (bash) and windows (cmd.exe). I want to port this to powershell.
How do I set environment variables in powershell by calling python script that prints $env:myVar=myvalue
and causes my environment variable to persist in the powershell.
In Bash I can use a bash function to call my python script which prints export var=value to stdout and the function will set the environment variables in my shell. This will also work in windows cmd shell by calling a .bat file.
I cannot figure out how to do this in powershell. I think it should be something like this:
setvar.ps1:
function SETVAR {c:\python26\python.exe varconfig.py }
varconfig.py:
import sys
print >> sys.stdout, '$env:myVar=foo'