This is something I saw here https://github.com/stsp/dosemu2/issues/746#issuecomment-453787916 but have verified by making a making two batch files:
SET_EL.BAT
EXIT 1
TEST_EL.BAT
CALL SET_EL.BAT
IF %ERRORLEVEL%==1 ECHO PASS
IF NOT %ERRORLEVEL%==1 ECHO FAIL
C:> TEST_EL
FAIL
Hi,
FreeCOM does support %ERRORLEVEL% and the FDI the FreeDOS Installer for version 1.2 & the upcoming 1.3 release make wide use of it. The issue is not %ERRORLEVEL%. But, appears to be the handling of the ** EXIT 1** command.
To demonstrate that %ERRORLEVEL% functions properly make sure you have V8Power Tools (On the FreeDOS 1.2 release media). Then simply replace EXIT 1 with verrlvl 1 and then it works.
Oops, I didn't realise that "exit 1" was a cmd.exe thing.
Is it possible to make freecom exit with the error level of the last
command as mentioned in the dosemu bug above ?
I'm not a FreeCOM expert. But AFAIK, there is no built in way to do that. This is one of the reasons the verrlvl program exists. Thankfully, V8Power Tools is installed by default in all types (Lite & Full) versions of the FreeDOS 1.2 and upcoming 1.3 release. So, the following simple batch logic will accomplish the same thing as that EXIT command.
All executables reset the ERRORLEVEL on exit. So, you must insure you execute nothing after setting the ERRORLEVEL. For example, the following WOULD NOT work and the batch would exit with ERRORLEVEL=0
Last edit: Shidel 2019-01-30
Correct, all versions of MS-DOS did not recognize parameters to EXIT. The EXIT command would simply exit.
In at least some versions of Windows, EXIT can accept parameters:
EXIT [/B] [errlevel]
The /B option would exit just the .BAT it was running, not the shell. Providing an errlevel also set the %ERRORLEVEL% to that value.
Can this thread be closed?
Yes, feel free to close this.