Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can call your subroutines like so:</p> <pre><code>call :b||exit /b 1 </code></pre> <p>which is equivalent to</p> <pre><code>call :b if errorlevel 1 exit /b 1 </code></pre> <p>It's slightly shorter and saves you one line, but it's still not ideal, I agree.</p> <p>Other than that I don't see a way.</p> <p><strong>EDIT:</strong> Ok, I got a way, but it's Pure Evil™.</p> <p>Misusing the maximum stack size, and therefore recursion limit, we create another subroutine which simply exhausts the stack by recursively calling itself:</p> <pre><code>@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 </code></pre> <p>This, however, will result in the nasty error message</p> <pre> ****** 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 ****** </pre> <p>Also, it will take around 2 seconds on my machine.</p> <p>You can suppress the error message by altering the <code>call</code> statement as follows:</p> <pre><code>call :exit &gt;nul 2&gt;&amp;1 </code></pre> <p>which will redirect everything it wants to output into a great void.</p> <p>But considering the time it takes to fill the stack I think the first variant would be easier.</p> <p>I was also contemplating using a second batch file, which, when run without <code>call</code> would essentially stop the first one. But somehow that doesn't play well with subroutines. Unrolling the call stack seemingly still takes place.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload