General discussion

  • Creator
    Topic
  • #2073532

    Setting the errorlevel?

    Locked

    by rejohnson ·

    I need to reset the errorlevel in a DOS batch file to return a 0 (zero) on exit. Anybody know an easy way to do that?

    Thanks,

    Russell

All Comments

  • Author
    Replies
    • #3894493

      Setting the errorlevel?

      by jesalyer ·

      In reply to Setting the errorlevel?

      ZDNet published a utility several years ago that does that. DCH1.01 and Enquire v2.7 are both available there and both should do what you want.

      jeff s
      spanish support analyst

      • #3894481

        Setting the errorlevel?

        by rejohnson ·

        In reply to Setting the errorlevel?

        Unfortunately, both utilities require keyboard input to set the errorlevel accordingly. I want to set it within the batch file (e.g., set errorlevel = 0)

        Thanks anyway.

    • #3894485

      Setting the errorlevel?

      by guy ·

      In reply to Setting the errorlevel?

      Is this what you are looking for? Technet even includes DOS stuff! Technet ref Q57658

      If you are writing a program that is going to be invoked from within an MS-DOS
      batch file that uses the IF ERRORLEVEL command, you can use Interrupt 21H
      Function 4CH, “Terminate Process with Return Code” to set the errorlevel in your
      program. This function terminates the program and returns the errorlevel to the
      parent process, which in this case is COMMAND.COM running the batch file.

      The parametersfor Interrupt 21H, Function 4CH are AH = 4CH, AL = errorlevel,
      followed by a call to Interrupt 21H. The errorlevel can be any value in the
      range 0 to 255 (0 to FF, hexadecimal).

    • #3894480

      Setting the errorlevel?

      by tchieng ·

      In reply to Setting the errorlevel?

      The easiest way to do it is simply write a utility program in Pascal and include that program in the batch file.

      program Seterror;
      begin
      halt(0);
      end.

      You can even do it in C. Don’t have a compiler? I can email it to you if you need it…

Viewing 2 reply threads