Skip to content

Instantly share code, notes, and snippets.

@Nexuapex
Created March 6, 2015 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nexuapex/a4527f92266d5a271ed6 to your computer and use it in GitHub Desktop.
Save Nexuapex/a4527f92266d5a271ed6 to your computer and use it in GitHub Desktop.
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