Created
March 6, 2015 17:18
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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