terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Path variable from the environment is not respected

Open 0xEDApps opened this issue 1 year ago • 9 comments

Windows Terminal version

1.22.240926002-preview

Windows build number

10.0.22621.819

Other Software

No response

Steps to reproduce

run: cmd.exe type: set path=c:\tweet;%path% type your path to terminal: "C:\Users\Admino\AppData\Local\Temp\WindowsTerminal\x64\WindowsTerminal.exe" open a cmd window in terminal and type: path

WindowsTerminal.exe shows the right path "c:\tweet;...." OpenConsole.exe also shows the right path "c:\tweet;...." but then cmd.exe has a different path

Expected Behavior

to see the active environment to see "c:\tweet"

Actual Behavior

shows the wrong path probably the environment is retrieved from the registry instead of the environment

0xEDApps avatar Oct 10 '24 08:10 0xEDApps

Checked with ProcessHacker to see the environment of individual executables

WindowsTerminal.exe shows the right path "c:\tweet;...." OpenConsole.exe also shows the right path "c:\tweet;...." cmd.exe has a different path

0xEDApps avatar Oct 10 '24 08:10 0xEDApps

Windows Terminal treats each tab and pane like a "container" of sorts. Each one gets its own fresh environment variables. You can disable that behavior here:

Image

lhecker avatar Oct 10 '24 11:10 lhecker

i see, indeed that works for new tabs but not for the one that is there when launched.

i also use these settings default profile: Command Prompt when terminal starts: open tab with default profile

0xEDApps avatar Oct 10 '24 12:10 0xEDApps

Also it does not show the correct path wen a tab is created with a new instance.

i have this setting new instance behavior: attach to the most recently used window

0xEDApps avatar Oct 10 '24 12:10 0xEDApps

Thanks for filing! Assuming Windows Terminal is set as your default terminal, start cmd should create a new window and immediately hand off to windows terminal, which would then have the expected environment block. This can be used as a workaround for your scenario. If you do wt new-tab -w0 cmd, that should work too. Does that work for you ?

Note #16226 may be involved here.

carlos-zamora avatar Oct 16 '24 21:10 carlos-zamora

Thanks for filing! Assuming Windows Terminal is set as your default terminal

Don't even know how to do that, it most likely can't be automated as MS implemented encryption for default file associations, so no it is not the default

Does that work for you ?

it does, but not my preferred solution

Note #16226 may be involved here.

Good find buddy Indeed, seems to be a reoccurring issue, you can not expect all users to start hunting for command line parameters, when the default behaviour is that a app inherits the environment from the caller. I used --inheritEnvironment from there as the cleaner outcome

To bad MS does not respect the environment and reads the registry instead, now many other devellopers also do that, a example WindowsTerminal writes to %LocalAppdata% but uses the one from the registry, i am not gonna mess with that, i attempted it years ago, but that is a global change and all other crappie apps will start to write at the new location too, so sad :( Maybe that should be a different issue.

0xEDApps avatar Oct 17 '24 06:10 0xEDApps

i am not gonna mess with that, i attempted it years ago, but that is a global change and all other crappie apps will start to write at the new location too, so sad :( Maybe that should be a different issue.

You must know that redirecting the known folders like AppData/LocalAppData is not supported. Please don't file bugs on us, or anyone else, for that.

DHowett avatar Oct 17 '24 15:10 DHowett

Thanks for filing! Assuming Windows Terminal is set as your default terminal

Don't even know how to do that, it most likely can't be automated as MS implemented encryption for default file associations, so no it is not the default

Windows Terminal is the default console host on your version of Windows unless you've turned it off explicitly, and it does not work by using "file associations".

DHowett avatar Oct 17 '24 15:10 DHowett

Windows Terminal is the default console host on your version of Windows unless you've turned it off explicitly, and it does not work by using "file associations".

Doubt that, i am on win 11 and never have i seen "windows terminal" it always shows cmd.exe or consolehost.exe

0xEDApps avatar Oct 17 '24 15:10 0xEDApps

At its heart, this is a /duplicate of #15496.

You can use the --inheritEnvironment argument or the profile setting compatibility.reloadEnvironmentVariables (set to false).

DHowett avatar Oct 23 '24 21:10 DHowett

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!