stting environment variables in powershell by calling python script that prints $env:myVar=myvalue

Posted by leeg on Stack Overflow See other posts from Stack Overflow or by leeg
Published on 2013-11-03T06:05:27Z Indexed on 2013/11/03 9:53 UTC
Read the original article Hit count: 242

Filed under:
|
|
|
|

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'

© Stack Overflow or respective owner

Related posts about python

Related posts about linux