-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Environment variables in path are not expanded in integrated terminal or Code-launched command prompt #26048
Comments
@wrummler What's the output of this?
Also can you share your settings.json file? |
Within integrated terminal (unexpanded NVM path variables):
Within standalone terminal (correctly expanded path variables):
Same contrasting behavior when I switch to CMD as integrated terminal shell. User settings:
Workspace settings:
|
@daviwil @joaomoreno have you ever seen this? Environment variables in the %PATH% not being expanded? |
Another possibly interesting detail: When I launch a standalone terminal from within Code via Ctrl+Shift+C and run When I launch a standalone terminal otherwise (e.g. Windows key; "cmd"; Enter key) and run |
Never seen this, no. |
Another detail: When I run Code as administrator, this doesn't happen. Environment variables expand as expected. Why would this behavior have changed from 1.11 to 1.12? Is it really a change with Code or is it some coincidence with my particular machine and account configuration? (Not demanding answers, just trying to actively rubberduck.) |
I'm seeing a different symptom of what is probably the same issue... The following in settings.json fails to start the shell with error code 1, replacing the environment variable with the hard-coded path works, as does putting
Work-around, of course, is to hard-code the path, but I'm syncing settings between different computers where that path is on different drives, which makes integrated-terminal a non-starter for me until either this is fixed or VSCode supports multiple terminals on a platform. |
@af4jm that one is a separate issue and needs VS Code to expand the variables, I suspect the OP's issue is related to PowerShell misbehaving. |
@Tyriar Command Prompt terminals demonstrate this behavior as well. The common factor is that the affected terminals are all launched by Code. Terminals launched outside of Code expand variables normally. Also, Code's terminals expand variables normally when running Code as an administrator (with a local machine account, vs. my "normal" account on my corporate domain). |
have you folks noticed that powershell user-defined functions and aliases are also not read when invoking a powershell from inside vscode? I'm thinking that this may be a related issue and wanted to check with you before registering a new issue. user alises are defined in user\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 ctrl-shift c creates powershell window, but user aliases are not read |
I am having the same issue with my home PC. I just downloaded VS code on my work PC this morning and no troubles with environment variables in integrated terminal. Tonight I downloaded the same version of VS code on my home PC and environment variables are not expanding, same issue as OP described. Both PCs are Windows 10 and up-to-date, the only different I can tell is that my work PC is AD joined and my home PC has an MS account. |
Today, after upgrading to VS Code 1.13 and also this Windows update "2017-06 Update for Windows 10 Version 1607 for x64-based Systems (KB3150513)" (and restarting my machine), I can no longer reproduce this issue. Unfortunately, I did not check with 1.13 prior to installing the Windows update, so I don't know whether it was 1.13 by itself. I could still reproduce the problems even just a few days ago, i.e. after I'd received "2017-05 Update for Windows 10 Version 1607 for x64-based Systems (KB3150513)" on May 31. I got some other updates a couple days ago, all of them for Office 2016 32-bit. Probably irrelevant, but mentioning it anyway for the sake of quasi-completeness. |
@wrummler what you mentioned also fixed my issue. I already had that windows update installed and version 1.13. The restart is what did it for me. The strange thing is that I did not have to restart my work PC. |
I can reproduce the issue again after updating to Code 1.13.1. Restarting my machine will "fix" it for a couple hours, but then the behavior comes back. |
I have this same problem. commands like npm, node, ng etc all work from a command prompt launched from windows. However the integrated terminal does not work. I'm using 1.15.1 |
@wrummler |
@TechMky I have no idea, unfortunately. I haven't had it happen again in quite a while, maybe a month or more now. My only guesses are either (a) it was fixed incidentally with some change to the integrated terminal (which has seen a lot of activity in the past couple months), or (b) it was due to some opaque and perhaps quasi-random corporate policy setting on my workstation at my job, and my employer's IT folks changed something in the automatic remote configuration they perform over their network. Sorry to not be able to help! |
It seems I'm having this issue too. |
I also happen to have this problem. I am using the wsl bash as integrated terminal and have defined a variable "SOME_VAR" : "/some/path/to/somewhere" in settings.json (terminal.integrated.env.windows) which I use as a home directory in tasks.json. But ${env:SOME_VAR} will not be resolved / resolved to nothing. I tried running as administrator but it did not work for me. |
Not sure if this will help but I was able to set environment variables and append to the integrated terminal Path variable by adding the following settings, (using Windows PowerShell as the terminal):
|
I'm having the exact same issue. Windows 10, VS code version 1.18.1. Could it be an issue with the IDE impersonating your user context to launch the session? I do have UAC set on medium settings. I haven't tried disabling UAC yet but it may get to that point if nothing else works. |
Try that
|
@tyelford Wtf? I recently subscribed to this issue because seen exact same magical behavior when variables are not available UNTIL computer restart. VS Code restart didn't help. It's definitely not an issue of Windows, because in any other place such as cmd or power shell everything worked as expected. |
@inliquid are you certain you closed all VS Code windows? The terminal environment is derived from the single "main process" of VS Code which only goes down and gets a refreshed environment after all windows are closed down. There is also another issue open around fetching a fresh environment block on Windows for terminals which won't be closing 👉 #47816 |
@Tyriar I'm pretty sure of what I'm doing. |
@inliquid the next time it happens you can open devtools (via Help menu), go to the console and check |
Similar issue here, VSCode doesn't correctly expand system environment variables. Latest VSCode version, Windows 10. Partial output of
Also of note is that The referenced variable does exist and is also listed by VSCode under Same with
In an external, regularly launched terminal (Powershell or CMD) everything is expanded like expected:
I will check if I notice anything in trace log when I get the time. Looking at the |
@joaomoreno @deepak1556 @bpasero have you ever got reports on the main processes' environment variables not being resolved properly? This definitely isn't a terminal issue as the window |
You mean our call to |
@bpasero not sure if that's to blame but it does fetch the environment. I've never reproduced this problem but |
I believe this is a Windows issue: https://stackoverflow.com/questions/25324354/windows-batch-files-what-is-variable-expansion-and-what-does-enabledelayedexpa Not sure each process is responsible to compute the expansion if they are spawned in an environment in which vars aren't already expanded... |
@joaomoreno should it not be a noop and we expand there just in case they're not already for some reason? |
I'm pretty sure you'd break other stuff by doing that: variable values containing two |
How do regularly launched CMD and Powershell have properly expanded variables then? There has to exist a standard mechanism that Microsoft is using for those I assume. I also think that I noticed the user profile directory is stored in the On that page is a reference to the It might be as simple as calling that function on startup? It would then only be important to call it with the raw unexpanded strings instead of those already expanded with system defaults as is happening now. |
@Systemcluster might have something to do with it; are you using the system install or the user install? |
@Tyriar I'm using the user install (in AppData). |
@TylerLeonhardt might have asked you before but do you know why some env variables would not get resolved properly by the time we get them? If we try to resolve them potentially again we could break things (eg. have %FOO% as a already resolved value of an environment variable?). |
This issue might be related. It's a bit older, but describes the same observation as in my comment above and contains some additional context. |
Since it happens erratically, with expandable variables that contains other expandable variables, maybe it's related to the behavior of CreateEnvironmentBlock that is described here: |
It's looking more and more like this is not something we can fix on our end. On Windows we just use the environment we're given by node in electron afaik, if it's not expanded as expected it should be fixed where ever the native calls are that are creating the environment block in the first place. |
This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines. Happy Coding! |
Sorry to barge in here but it seems VSCode's PowerShell instance sees neither my own User Environment Variables not the System Environment variables. How can I set an environment variable once and for all which VSCode sees?? |
Steps to reproduce
node
, press enter.The terminal output is
node : The term 'node' is not recognized [...]
.Recognition of
node
still fails if I instead first entercmd
(which works and opens a subshell) and try it there.More details
Also occurs for
npm
andnvm
, but not forgit
. Built-ins and other standard things (likedir
,cmd
,notepad
, etc) work fine.I use nvm-windows. It's managing 7.4.0 and 7.9.0 for me. This behavior happens when using either.
Was occurring in non-integrated CMD and PS terminals until I restarted my computer. After restarting my computer, non-integrated terminals do not show this behavior (and so are a workaround for me right now). I had not restarted my computer since initially updating from 1.11 to 1.12.0 a few days ago, and I hadn't tried any of this since before that.
The text was updated successfully, but these errors were encountered: