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

MINOR: Environment Variable in CMD Prompt not resolved. #8096

Closed
FDFessler opened this issue Oct 29, 2020 · 7 comments
Closed

MINOR: Environment Variable in CMD Prompt not resolved. #8096

FDFessler opened this issue Oct 29, 2020 · 7 comments
Labels
Product-Cmd.exe The issue is related to the legacy command interpreter, CMD.exe. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@FDFessler
Copy link

This is VERY MINOR: Environment Variable in CMD Prompt not resolved.

Environment

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd]
Microsoft Windows [Version 10.0.19041.572]
Windows Terminal version (if applicable):
Windows Terminal Preview
Version: 1.4.2652.0
Settings for Command Prompt:
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "Command Prompt",
                "commandline": "cmd.exe",
                "startingDirectory": "P:\\",
                "hidden": false

Any other software?

Steps to reproduce

Launch Command Prompt in WT

Expected behavior

While I have a fairly long (and "crazy") prompt string in my environment settings it seems to do everything right except resolve an environment name (in this case my PC name %ComputerName%).
Current Prompt:
$E[1;33;45m[$D--$T$H$H$H$H$H$H]$S$E[7;33;44m$C$N:$Q$M$H$F$$E[0;34;47m$P$E[0;37;44m$[%ComputerName%]:$S$+$G$S
Prompt should look like this:
[10/29/2020-- 9:38] (P:=\ServerName\Dir1\Dir2)
P:
[MyActualPCName]: >

Actual behavior

I get this (with all the correct colors) but the %ComputerName% is not resolved.
[10/29/2020-- 9:32] (P:=\ServerName\Dir1\Dir2)
P:
[%ComputerName%]: >

@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 Oct 29, 2020
@zadjii-msft
Copy link
Member

So here's the weird thing with the PROMPT command - environment variables in it are only expanded when the command is run, not when the prompt is displayed. So when you do:

PROMPT %COMPUTERNAME%$g

cmd evaluates %COMPUTERNAME% to whatever (in my case, MIGRIE-SLAPTOP, then sets the prompt to MIGRIE-SLAPTOP$g

image

So I'm betting that your prompt variable literally has %ComputerName% in it, rather than the evaluated value of %ComputerName%, right?

@zadjii-msft zadjii-msft added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Product-Cmd.exe The issue is related to the legacy command interpreter, CMD.exe. labels Oct 29, 2020
@FDFessler
Copy link
Author

FDFessler commented Oct 29, 2020

That is correct and is what I posted above.
It works if I just open a "normal" CMD prompt however. So, I'm OK if this is a limitation, just wanted to make sure this was not an "oversite".
You can duplicate the problem very easily by setting your Prompt environment string to just %ComputerName%$g
... and then seeing the difference between standard CMD prompt and WT CMD prompt.

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Oct 29, 2020
@DHowett
Copy link
Member

DHowett commented Oct 29, 2020

This is likely a side effect of us giving CMD a new environment block. I swear sometimes, this OS is too fragile to write code for.

@FDFessler
Copy link
Author

This NOT a big deal (very minor IMO), I can just run my prompt manually after opening the COMMAND Prompt windows in WT. Like I said earlier, just wanted to make sure this was not an "oversite".
Thanks.

@LuanVSO
Copy link
Contributor

LuanVSO commented Nov 1, 2020

this works for me
image
don't know why though ¯\_(ツ)_/¯

@DHowett
Copy link
Member

DHowett commented Nov 20, 2020

Alright, after sitting on this issue for a while I've come to a conclusion.

This is technically the same as #7418, but for a different reason. The solution to both is the same, however: we have to do a 3-way merge and expand the environment block in Terminal before we start the next process.

Thanks 😄

/dup #7418

@ghost
Copy link

ghost commented Nov 20, 2020

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!

@ghost ghost closed this as completed Nov 20, 2020
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed 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 Needs-Attention The core contributors need to come back around and look at this ASAP. labels Nov 20, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product-Cmd.exe The issue is related to the legacy command interpreter, CMD.exe. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

4 participants