I’m trying to automate a program I made with a test suite via a .cmd file.
I can get the program that I ran’s return code via %errorlevel%.
My program has certain return codes for each type of error.
For example:
1 – means failed for such and such a reason
2 – means failed for some other reason
…
echo FAILED: Test case failed, error level: %errorlevel% >> TestSuite1Log.txt
Instead I’d like to somehow say:
echo FAILED: Test case failed, error reason: lookupError(%errorlevel%) >> TestSuite1Log.txt
Is this possible with a .bat file? Or do I have to move to a scripting language like python/perl?
You can do this quite neatly with the
ENABLEDELAYEDEXPANSIONoption. This allows you to use!as variable marker that is evaluated after%.Type
HELP SETLOCALandHELP SETat a command prompt for more information on delayed expansion.