Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I get this:
****** B A T C H R E C U R S I O N exceeds STACK limits ******
Recursion Count=645, Stack Usage=90 percent
****** B A T C H PROCESSING IS A B O R T E D ******when I run this BAT in w2k:
::**
@echo off > quit.bat
:main
for /L %%N in (1,1,10000) do call :generate
goto :eof
:generate
echo %random% >> random.log
goto :main
::**
Without the goto :main it's OK.
What's going on here?
TIA
M2
If at first you don't succeed, you're about average.

Here's a little incidental intelligence from M$.
In XP config.nt, the defauly stacks:
IBM PC, IBM PC/XT, IBM PC-Portable 0,0
other 9,128
I guess I'll take my chances with 'other'; don't think I want to run XP on PC/XT.
Unless I eat a whole jar of downers first.
M2
If at first you don't succeed, you're about average.

Why did you code a "GoTo :main" at the end of the :generate internall subroutine? In that way you trig a (not required) recursive call of the batch's body itself.
To end a subroutine you have to code just "GoTo :EOF" (that returns to OS if part of the main). You do not need to explicitly set up a loop as the Call is performed by the semantic of For 10000 times.

Hi IVO,
Yes, inthis case since there is nothing else to do it has no prctical effect.
But it 'falls through'.
With this code:
::**
@echo off > quit.bat:main
for /L %%N in (1,1,10000) do call :generate
goto :eof
:generate
echo %random% >> random.log
:somesub
echo somesub
:eof
::**
it does the echo somesub many [probably 10000] times. Which means it has fallen through the :somesub label.
So how to tell :main where :generate ends?
M2
If at first you don't succeed, you're about average.

Hi M2,
you have to code a GoTo :EOF either after the Echo %random% either after the Echo somesub, and the :EOF does not need to be declared as it is hardwired in NT interpreter.
GoTo :EOF means "Return from Subroutine" or (if in main) "Return to the System". see GoTo /? and Call /? for a short tutorial.
So you have to code
:Generate
Echo %random% >> random.log
GoTo :EOF:somesub
echo somesub
GoTo :EOFwithout declaring the :EOF label.

Hi Mechanic
This handles the stack correctly without droping through.
for /L %%N in (1,1,10000) do call :generate
echo Here
exit /b:generate
%random% >> random.log
exit /b

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |