Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Refresh Windows environment variable, if Sublime Text restart #1684

Closed
Kristinita opened this issue Apr 25, 2017 · 2 comments

Comments

@Kristinita
Copy link

Kristinita commented Apr 25, 2017

Possibly related question, because I run terminal use ConEmuOpen package. If I run ConEmu not from Sublime Text, I don't get this problem.

1. Summary

If I change PATH user environment variable, I need restart Windows, that changes will apply in Sublime Text plugins. It would be nice, if will be enough to restart Sublime Text, not Windows.

2. Settings

For example, I install Selenium → I install Geckodriver → I add path to Geckodriver as value of PATH user environment variable.

I have a test plugin for test the Selenium working in Sublime Text.

import sublime
import sublime_plugin
import sys

try:
    import unittest2 as unittest
except ImportError:
    import unittest

sys.path.append("C:\Python36\Lib\site-packages")
from selenium import webdriver


def run_tests(view):
    browser = webdriver.Firefox()
    browser.get('https://google.com')


class RunSeleniumCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        run_tests(self.view)

3. Steps to reproduce

I reproduce the problem in a version of Sublime Text without plugins and user settings.

I reproduce the problem for another CLI applications.

I restart Sublime Text → I open any file in Sublime Text → I run window.run_command('run_selenium') in Sublime Text console.

4. Actual behavior

>>> window.run_command('run_selenium')
Traceback (most recent call last):
  File "./python3.3/subprocess.py", line 1104, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python36\Lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1110, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Sublime Text 3 x64\sublime_plugin.py", line 818, in run_
    return self.run(edit)
  File "D:\Sublime Text 3 x64\Data\Packages\TestPlugin\Selenium.py", line 26, in run
    run_tests(self.view)
  File "D:\Sublime Text 3 x64\Data\Packages\TestPlugin\Selenium.py", line 19, in run_tests
    browser = webdriver.Firefox()
  File "C:\Python36\Lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
    self.service.start()
  File "C:\Python36\Lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

5. Expected behavior

If I restart Windows, plugin successful test for me, I don't get stack trace.

6. Environment

Operating system and version:
Windows 10 Enterprise LTSB 64-bit EN
Sublime Text:
Build 3126

Thanks.

@keith-hall
Copy link
Collaborator

Based on the following in Windows 7:

  1. Open Sublime Text
  2. In the ST console, type import os; os.environ.get('test')
  3. the result is blank
  4. Open Command Prompt
  5. Type set test=hello world Enter
  6. Close ST
  7. back in Command Prompt, write "%PROGRAMFILES%\Sublime Text 3\subl" Enter
  8. In the ST console, type import os; os.environ.get('test')
  9. the result is 'hello world2'

I'd say ST is working correctly, and the problem is likely not with ST.

@FichteFoll
Copy link
Collaborator

This is standard Windows behavior for all applications (OS behavior, even) and certainly won't be changed.

Changes to the environment variables are only carried over to child processes but never to parents. If you change environment variables in the Windows settings, they get immediately carried over to explorer.exe, meaning any process you launch from it gets the updated environment variables, but no currently running process. Subsequently, any process launched from a currently running (and un-updated) process will also not inherit the updated env.

Basically, you need to relaunch conemu to make it pick up the environment changes (or do it directly in the cmd process it hosts using the method @keith-hall described) or launch ST from your desktop, i.e. via explorer.exe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants