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

wt.exe ignores environment of parent (calling) process #11094

Closed
rashil2000 opened this issue Aug 31, 2021 · 8 comments
Closed

wt.exe ignores environment of parent (calling) process #11094

rashil2000 opened this issue Aug 31, 2021 · 8 comments
Labels
Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting

Comments

@rashil2000
Copy link
Contributor

Windows Terminal version (or Windows build number)

10.0.19043.1165 1.10.1933.0

Other Software

No response

Steps to reproduce

  1. Open up cmd.exe (in conhost)
  2. Do set SOME_VAR=some_value
  3. Type conhost. In the newly launched window, check for SOME_VAR variable. It'll be set. Close this new window.
  4. In the original cmd.exe shell, type wt. In the newly launched window, check for SOME_VAR variable. It'll be absent.

Expected Behavior

I expect any new processes launched from the original shell to inherit the parent's environment.

Actual Behavior

The wt.exe executable is probably the first ever process I have seen (in my limited experience) that ignores the parent's environment. All other processes (including conhost) inherit the environment.

Note that I searched for similar issues, and found numerous ones pertaining to refreshing the environment variables automatically for new tabs/panes. This is not that.

There is actually an issue - #4259 - which slightly mentions this sort of thing, but again the issue title there is regarding panes and not the process in general.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Aug 31, 2021
@rashil2000
Copy link
Contributor Author

On second thought, I now realize why this behaviour is by design. Each new window/tab/pane fetches the environment block from the system itself (the registry, perhaps?). If it were to inherit it from the parent, it won't have up to date values.

Is this reasoning correct? Please close this if it is 😅.

@zadjii-msft
Copy link
Member

Each new window/tab/pane fetches the environment block from the system

I believe it only does this on main - I don't think we actually shipped that code, because it broke... pwsh or scoop or something like that. #9741? #7418 maybe? @DHowett You remember that one better than me.

@DHowett
Copy link
Member

DHowett commented Sep 1, 2021

It's... complicated. @rashil2000, you're right that it keeps the environment up to date. However, it should try to merge the environment if possible. 😄

@rashil2000
Copy link
Contributor Author

rashil2000 commented Sep 1, 2021

I'm curious to know what it'll do in case of "merge conflicts" 😅

Like if I set SOME_VAR in both the calling process and in the Start Menu->Environment Variables dialog.

@eryksun
Copy link

eryksun commented Sep 1, 2021

However, it should try to merge the environment if possible.

I'd be worried that automated merging could create an inconsistent state, with conflicting variables or values. I see no reason to deviate from Explorer's behavior in this regard. To that end, Terminal would listen for WM_SETTTINGCHANGE "Environment" window messages, for which it would reload the environment block that's used for new tabs. Maybe it could also support an OSC sequence that contains a serialized environment block, which sets a per-tab or per-pane environment for use when duplicating or splitting a tab.

@jporkka
Copy link

jporkka commented Nov 17, 2021

I second that thought -- it should not try to merge environment variables.
Each new tab just gets a fresh copy of the system environment after a WM_SETTINGCHANGE -- Just like Explorer does.

Merging will likely end badly - as there are complex scenarios, and it is unlikely that users would foresee this and will get surprised.

Maybe a cmdline option to control if it should listen for WM_SETTINGCHANGE? So if users really want the terminal to only inherit their env vars from the parent process they can get it.

@DHowett
Copy link
Member

DHowett commented Jan 11, 2022

Hey all! Thanks for the discussion here. We've decided to make the call:

We aren't going to merge environment variables, and applications spawned inside a Terminal will always have an "up to date" view of the user's environment. How we achieve this is up in the air (whether we can rely on RegenerateUserEnvironment or if we have to "bless" our own version of it moving forward), but given that Terminal (1) is multiprocess and (2) comes with a "remote" control frontend that can open new tabs in existing windows the ownership and the provenance of the environment was never a sure thing.

The best thing we can do is always give you a consistent new environment -- trying to guess which one you wanted and what you wanted from that one will result in us accidentally being wrong, rather than being consistent.

Thanks!

@DHowett DHowett closed this as completed Jan 11, 2022
@DHowett
Copy link
Member

DHowett commented Jan 11, 2022

Please follow #1125 for future updates about this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting
Projects
None yet
Development

No branches or pull requests

5 participants