Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 246183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:09:04+00:00 2026-05-11T21:09:04+00:00

I’ve got a windows batch file, with a few sub-routines in it something like

  • 0

I’ve got a windows batch file, with a few sub-routines in it something like this:

call :a
goto :eof

:a
call :b
goto :eof

:b
:: How do I directly exit here from here?
goto :eof

I’m running this in a cmd window on Vista.
If I detect an error somewhere in the batch file, I want it to exit with a non-zero errorlevel. Is there anything I can write in the routine :b that will cause the batch file to terminate like this.

  • I’ve tried ‘exit’, which closes the entire cmd window. That’s not what I want.
  • I’ve tried ‘exit /B 1’. That returns to the previous routine. To use this scheme after every ‘call’ I’d have to carefully write ‘if errorlevel 1 exit /B 1’ after every single ‘call’ to pass the error back up the call stack. I’d prefer not to have to write this line after every call.

This article was interesting, but non of the alternatives behave in the way I want. http://www.computerhope.com/exithlp.htm

Is there another way?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:09:04+00:00Added an answer on May 11, 2026 at 9:09 pm

    You can call your subroutines like so:

    call :b||exit /b 1
    

    which is equivalent to

    call :b
    if errorlevel 1 exit /b 1
    

    It’s slightly shorter and saves you one line, but it’s still not ideal, I agree.

    Other than that I don’t see a way.

    EDIT: Ok, I got a way, but it’s Pure Evil™.

    Misusing the maximum stack size, and therefore recursion limit, we create another subroutine which simply exhausts the stack by recursively calling itself:

    @echo off
    echo Calling a
    call :a
    echo Called a
    goto :eof
    :a
    echo Calling b
    call :b
    echo Called b
    goto :eof
    :b
    echo Trying to exit
    call :exit
    goto :eof
    :exit
    call :exit
    

    This, however, will result in the nasty error message

    ******  B A T C H   R E C U R S I O N  exceeds STACK limits ******
    Recursion Count=704, Stack Usage=90 percent
    ******       B A T C H   PROCESSING IS   A B O R T E D      ******
    

    Also, it will take around 2 seconds on my machine.

    You can suppress the error message by altering the call statement as follows:

    call :exit >nul 2>&1
    

    which will redirect everything it wants to output into a great void.

    But considering the time it takes to fill the stack I think the first variant would be easier.

    I was also contemplating using a second batch file, which, when run without call would essentially stop the first one. But somehow that doesn’t play well with subroutines. Unrolling the call stack seemingly still takes place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 152k
  • Answers 152k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This depends on the fact that input elements don't contain… May 12, 2026 at 10:07 am
  • Editorial Team
    Editorial Team added an answer Use .live, better than having hundreds of separate click events.… May 12, 2026 at 10:07 am
  • Editorial Team
    Editorial Team added an answer It sounds like you're trying to bind a list of… May 12, 2026 at 10:07 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.