Menu

#310 FreeCOM 0.85 doesn't track IF ERRORLEVEL

freedos13
closed
None
5
2021-07-19
2021-06-13
Jim Hall
No

Burkhard M reported this to me via email, and I am adding my own additional info:

FreeCOM 0.85 does not track IF ERRORLEVEL correctly. I haven't looked through the code yet, but it seems as though FreeCOM 0.85 is treating IF ERROLEVEL like the return code was zero. (But the behavior is correct in 0.84 releases.)

The ERRORLEVEL environment variable is getting set correctly.

Discussion

  • Jim Hall

    Jim Hall - 2021-06-13
    • Group: freedos12 --> freedos13
     
  • Jim Hall

    Jim Hall - 2021-06-13

    Additional debugging info - I wrote this simple program to set the ERRORLEVEL to a predictable value:

    #include <stdio.h>
    #include <stdlib.h>
    
    int
    main(int argc, char **argv)
    {
      int ret;
    
      if (argc > 1) {
        ret = atoi(argv[1]);
        printf("%s => %d\n", argv[1], ret);
      }
      else {
        ret = 0;
        puts("no option => 0");
      }
    
      return ret;
    }
    

    And this T.BAT file:

    @echo off
    errlevel %1
    IF ERRORLEVEL 4 GOTO FOUR
    IF ERRORLEVEL 3 GOTO THREE
    IF ERRORLEVEL 2 GOTO TWO
    IF ERRORLEVEL 1 GOTO ONE
    
    echo Zero
    GOTO END
    
    :FOUR
    echo Four
    GOTO END
    
    :THREE
    echo Three
    GOTO END
    
    :TWO
    echo Two
    GOTO END
    
    :ONE
    echo One
    
    :END
    echo Done
    

    And this T2.BAT:

    @ECHO OFF
    ERRLEVEL %1
    ECHO %ERRORLEVEL%
    

    Calling "T 1" correctly prints "One" in the old versions of FreeCOM. But prints "Zero" in all builds of FreeCOM 0.85

    Calling "T2 3" correctly prints "3" in all builds, old and new.

     
  • Kenneth Davis

    Kenneth Davis - 2021-06-13

    I will look into the issue and try to get a fix this week. I will test but do you know off hand which if 0.84 pre 7 worked correctly? or did it break in an earlier pre release?

     
  • Jim Hall

    Jim Hall - 2021-06-13

    It works correctly in 0.84-pre7

    Running "T 3" prints "Three" in 0.84-pre7

    Running "T2 4" prints "4" in 0.84-pre7

     
  • Kenneth Davis

    Kenneth Davis - 2021-06-17

    I added a version of your test batch file (errlvl.bat), the program to explicitly generate errorlevels (errlvl.c) already existed in the tests directory - to avoid any future regressions and test the fix see the errlvl.bat file added

     
  • Kenneth Davis

    Kenneth Davis - 2021-07-18

    This is resolved in 0.85a release. Please close bug.

     
  • Jim Hall

    Jim Hall - 2021-07-19
    • status: open --> closed
     
  • Jim Hall

    Jim Hall - 2021-07-19

    Thanks! Marked as closed

     

Log in to post a comment.