Today I revisited the amazing
%mm% macro, and I had a comment there that it errors out when the Batch file is opened by clicking (unlike when opened in CMD). Upon debugging, I realized that the "bug" is on the COLOR command which is used to set the errorlevel. Example:
Code: Select all
@echo off
color 00
echo(%errorlevel%
color
echo(%errorlevel%
pause
When the above code is opened in CMD, the output is "1" then "0", which is the
right output. On the other hand, when same is opened by double-clicking, the output is both "1", which (I think) means that the color command without parameters didn't "change" the color, hence didn't set the errorlevel to 0. Note that this happens regardless of whether the script is .bat or .cmd. Why this happens?
Maybe double-clicking is not the
right way to execute Batch scripts.
Is there a fix that still uses color command? If no, then what are some alternatives to setting errorlevel? Is
a "good" one?
Tested on a Windows 10 64-bit. Maybe I will also make another test on a different PC.
Thanks,
Meerkat