Skip to content

Instantly share code, notes, and snippets.

@Nexuapex Nexuapex/env.cmd
Created Mar 6, 2015

Embed
What would you like to do?
A Python script that injects environment variables into the calling cmd.exe shell.
@echo off
rem = """
rem This is a hybrid batch and Python script. The batch (right here) invokes
rem the Python script and treats its standard output as a list of environment
rem variables to set in the current environment.
rem The -x argument causes the Python interpreter to ignore the first line.
rem The -S argument disables the implicit 'site' package import (speed go fast).
FOR /F "tokens=1,2 delims==" %%v IN ('python -x -S "%~f0" %*') DO SET %%v=%%w
GOTO :eof
"""
import socket
print('TESTVAR1='+socket.gethostbyname(socket.gethostname()))
print('TESTVAR2=%TESTVAR1%')
print('TESTVAR3=three')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.