Skip to content

wt ignore env-vars set in the script launching it, due to new "auto reload system env vars with new window / tab" #15430

Closed as not planned
@eZioPan

Description

@eZioPan

Update:

for anyone encounter the same problem:

I suggest to set envrionment variables in Windows Terminal, and do not set env vars in script and let wt inherit it.

If you use powershell script, here is my solution:

$pre_cmd_string = {
    # do common pre run setup, set env vars, run some commands, etc...
    # DO NOT WRITE ANY COMMENTS IN THIS BLOCK, AND REMEMBER REMOVE US TOO
}.ToString()

<# prepare first pane...#>

$first_cmd_string = $pre_cmd_string + "`n" + { <#per pane setup code#> }.ToString()
$first_cmd_bytes = [System.Text.Encoding]::Unicode.GetBytes( $first_cmd_string )
$first_cmd_enc = [Convert]::ToBase64String( $first_cmd_bytes )

<# ... and #>
<# prepare rest of panes as above...#>

<# launching wt and launching powershell with EncodedCommand parm #>

wt pwsh.exe -ExecutionPolicy ByPass -NoExit -EncodedCommand $first_cmd_enc

Windows Terminal version

1.18.1421.0

Windows build number

10.0.19045.0

Other Software

PowerShell 7.4

Steps to reproduce

  1. open powershell open a standalone powershell commandline window (not in wt window)
  2. custom a env var $Env:MY_VAR="MY_VAL"
  3. launch a new Windows Terminal wt
  4. in new window (running powershell), type echo $Env:MY_VAR
  5. Nothing show up

after I disable compatibility.reloadEnvironmentVariables in global settings.json, new wt window inherit env var set in powershell

Expected Behavior

No response

Actual Behavior

see above

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions