I'd like to run this script at startup on a sublime text session:
import os
import sys
import re
import subprocess
from pprint import pprint
def check_vs_env():
try:
p = subprocess.Popen("cl",
stdout=subprocess.PIPE,
shell=False)
stdout, stderr = p.communicate()
print(stdout)
except:
print("Visual studio compiler not found!")
print('-' * 80)
check_vs_env()
print('-' * 80)
print("VS environment setup")
p = subprocess.Popen("vcvarsall.bat amd64 && set",
cwd=r"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC",
stdout=subprocess.PIPE,
shell=True)
stdout, stderr = p.communicate()
print("Finished VS environment setup [OK]")
print('-' * 80)
print("ST environment setup")
for varname, varvalue in re.findall(r'^(.*?)=(.*)', stdout.decode("utf-8"), re.MULTILINE):
os.environ[varname] = varvalue
print("ST environment setup [OK]")
print('-' * 80)
check_vs_env()
print('-' * 80)
Output:
--------------------------------------------------------------------------------
Visual studio compiler not found!
--------------------------------------------------------------------------------
VS environment setup
Finished VS environment setup [OK]
--------------------------------------------------------------------------------
ST environment setup
ST environment setup [OK]
--------------------------------------------------------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23918 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
b'usage: cl [ option... ] filename... [ /link linkoption... ]\r\n'
--------------------------------------------------------------------------------
So far so good, but once I check the os.environ in the SublimeText3 console it seems the new content is not persisted.
Any clue how to go about this?
ADDITIONAL NOTES
The communication from my script to SublimeText is not done properly.
On the other hand, modifying os.environ from SublimeText console and then read it from my script works ok.