Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
GeoffVass
- Posts: 11
- Joined: 04 Oct 2021 17:34
#1
Post
by GeoffVass » 04 Oct 2021 17:39
Just found one of my scripts broke on Windows 11.
I had something like this:
Code: Select all
SetLocal EnableDelayedExpansion
<do some stuff>
if defined Result (echo Success) else (echo Failure!!)
EndLocal
This has always worked, but on Windows 11 it glitches. You can probably guess the
in the echo command is the culprit.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 04 Oct 2021 21:45
Not explicitly understanding what you think the glitch is? There has always been an issue with displaying exclamations when delayed expansion is enabled.
-
GeoffVass
- Posts: 11
- Joined: 04 Oct 2021 17:34
#3
Post
by GeoffVass » 04 Oct 2021 23:28
The glitch is that I should never have used exclamation marks cosmetically. But it used to work, and now doesn't. So either Microsoft has fixed a bug in Windows 11, or introduced one. Anyway I've just removed the exclamation marks. My point is that it's weird to find some changed behavior in CMD.EXE so quickly.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#4
Post
by aGerman » 05 Oct 2021 02:18
You are showing us a piece of code but not what you get on Win 11 in comparison to what you got on Win 10 ¯\_(ツ)_/¯
Code: Select all
@echo off
SetLocal EnableDelayedExpansion
set "Result="
if defined Result (echo Success) else (echo Failure!!)
set "Result=X"
if defined Result (echo Success) else (echo Failure!!)
EndLocal
pause
Output on Win10:
Code: Select all
Failure
Success
Drücken Sie eine beliebige Taste . . .
Of course it's absolutely expected that the exclamation points are removed because they are treated as an empty/undefined variable if delayed expansion is enabled.
So if you take this example and run it on Win 11, what's the difference?
Steffen
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#5
Post
by aGerman » 05 Oct 2021 12:45
Alright, let me answer this question myself. Installed Win 11, ran the script, and the output is
Code: Select all
Failure
Success
Drücken Sie eine beliebige Taste . . .
The difference is that it shows up in a console window with round corners
Steffen
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#6
Post
by Squashman » 05 Oct 2021 12:52
aGerman wrote: ↑05 Oct 2021 12:45
The difference is that it shows up in a console window with round corners
I draw the line on round corners. Never upgrading to Windows 11!!
-
atfon
- Posts: 178
- Joined: 06 Oct 2017 07:33
#7
Post
by atfon » 05 Oct 2021 13:05
Squashman wrote: ↑05 Oct 2021 12:52
aGerman wrote: ↑05 Oct 2021 12:45
The difference is that it shows up in a console window with round corners
I draw the line on round corners. Never upgrading to Windows 11!!
Maybe write a script that converts round corners to square?
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#8
Post
by aGerman » 05 Oct 2021 13:28
I'm far too pragmatic to get upset about those details. As long as everything works I'm still ok if they make concave corners having flourish. After a few days I don't even notice it anymore