Menu

#228 FreeCom does not support %ERRORLEVEL%

freedos13
closed
nobody
None
5
2024-08-14
2019-01-13
Stuart Axon
No

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

Discussion

  • Shidel

    Shidel - 2019-01-30

    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.

     
    • Stuart Axon

      Stuart Axon - 2019-01-30

      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 ?

       
  • Shidel

    Shidel - 2019-01-30

    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.

    vecho /fLightRed I have a problem.
    verrlvl 1
    goto END
    :SUCCESS
    vecho /fLightGreen If it worked we would be here now.
    :END
    

    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

    verrlvl 1
    vecho /fLightRed I have a problem.
    goto END
    
     

    Last edit: Shidel 2019-01-30
  • Jim Hall

    Jim Hall - 2019-02-04

    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.

     
  • fritz.mueller

    fritz.mueller - 2024-08-05

    Can this thread be closed?

     
  • Stuart Axon

    Stuart Axon - 2024-08-06

    Yes, feel free to close this.

     
  • Shidel

    Shidel - 2024-08-14
    • status: open --> closed
     

Log in to post a comment.