microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.08k stars 8.24k forks source link

DOSKEY aliases work unexpectedly #16203

Open o-sdn-o opened 11 months ago

o-sdn-o commented 11 months ago

Windows Terminal version

current main

Windows build number

10.0.19045.3448

Other Software

No response

Steps to reproduce

According to https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/doskey

$T or $t Separates commands. Use either of these special characters to separate commands when you create macros or type commands on the doskey command line. These special characters are equivalent to using the ampersand (&) on a command line.

and https://ss64.com/nt/doskey.html

Advanced macro definitions:

$T If you put more than one command in a DOSKEY macro, use $T. to separate them. Equivalent to & in a batch file.

the following commands

doskey test=echo 123 $t echo 456
test

and

echo 123 & echo 456

should give the same output.

Expected Behavior

C:\Users\sdn>doskey test=echo 123 $t echo 456

C:\Users\sdn>test
123
456

C:\Users\sdn>

Actual Behavior

C:\Users\sdn>doskey test=echo 123 $t echo 456

C:\Users\sdn>test
123

C:\Users\sdn>456

C:\Users\sdn>

Related to #14991

DHowett commented 11 months ago

Say, does this work properly for you on 1.18?

DHowett commented 11 months ago

From my own testing:

rs1

chop is incapable of loading conhostv2 from rs1. I can't test earlier than rs2.

rs2

image

broken

rs3

image

broken

rs5

image

broken

19h1

image

broken

o-sdn-o commented 11 months ago

In release-1.18 branch the same result:

C:\Users\sdn>doskey test=echo 123 $t echo 456

C:\Users\sdn>test
123

C:\Users\sdn>456

C:\Users\sdn>
o-sdn-o commented 11 months ago

In NT3.51/Win2K/WinXP/7/8.1 the same result as in Win10,

but in Windows 3.11 slightly different result: image

Also, & does not work in Win311: image

o-sdn-o commented 11 months ago

It looks like the line command split (multicommand) first appeared in doskey and later in cmd.exe itself. And now if we suddenly decide to fix this behavior, we just need to replace $T with & during parsing the cooked read and send it to cmd.exe in one line without splitting into multiline.

237dmitry commented 11 months ago
doskey test=echo 123 ^& echo 345
o-sdn-o commented 11 months ago

In Win 3.11: image

In WinNT 3.51 image

In Win2K: image

In WinXP/7/8.1/10: image

o-sdn-o commented 11 months ago

We can look at the use of $t and ^& tags in batch files by searching on github.

o-sdn-o commented 11 months ago

So, it looks like this behavior has been going on since the beginning, when the TSR doskey was incorporated into the NT kernel.

DHowett commented 11 months ago

The issue is probably related to us printing the prompt again, not anything to do with us replacing $t with the right token. :)