1
Trying to automate some DOSBox scripting for an old program, I wanted to use the exit code usually in errorlevel
to control the program flow.
The input is given in a hello_db.bat
file:
@echo off
set msg=Hello
echo %msg%
dir
echo errorlevel = %errorlevel%
Then DOSBox is called with dosbox hello_db.bat
.
The output is:
Hello
{Listing from dir}
errorlevel =
So the %errorlevel%
expanded to an empty string instead of the exit code from the dir
command, where as the first msg
variable could expand correctly.
How can I make DOSBox expand the errorlevel
correctly in the script?
Short answer based on through answer by @phuclv:
The requirement was to insert a pause after the command if not OK (errorlevel != 0), so ended up doing:
set errorany=0
:: Command is inserted here...
if errorlevel 1 set errorany=1
:: Make pause if not OK
if %errorany%==1 pause
1Thanks a lot for the through answer; that is greatly appreciated :-) I have added a condensed solution to my question, to make it easier to apply for other that drop by. – Morten Zilmer – 2019-10-30T20:30:21.210