如何在Sublime Text上坚持env vars?

时间:2016-10-06 13:36:47

标签: python environment-variables sublimetext3

我想在启动时在一个崇高的文本会话上运行这个脚本:

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)

输出:

--------------------------------------------------------------------------------
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'
--------------------------------------------------------------------------------

到目前为止一切都那么好,但是一旦我检查了SublimeText3控制台中的os.environ,似乎新内容没有被保留。

有任何线索如何解决这个问题?

其他说明

从我的脚本到SublimeText的通信未正确完成。

另一方面,从SublimeText控制台修改os.environ然后从我的脚本中读取它可以正常工作。

0 个答案:

没有答案