Recursion Problem in Batch

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I'm having some problems with a recursion error in a batch file. The
error message is "BATCH RECURSION exceeds STACK limits" with an
additional line that indicates "Recursion Count=1265" and "Stack Usage=
90 percent." The batch is supposed to process lots of files (sometimes
a few hundred, sometimes a few thousand) in a particular directory on my
server.

The process moves files from one dir to another, runs a osql command on
files with a .log extension and then, 25 at a time, runs start to call
another external batch file that contains another osql command. The
process runs okay for approximately 7 days but dies with the above error
message. I've included the contents of the batch below. Any
suggestions would be welcome.

=========================================

1. @echo off
2. @title=Inventory Load

3. :TOP
4. cd \loading
5. if not exist err mkdir err
6. ECHO %time% Executing Load Inventory
7. osql -S mySQLServer -E -n -o err\%1.err -Q "EXEC
sqlDB1..spLoadInventory"
8. move c:\out\*.* c:\loading > nul

9.for %%a in (*.log) do echo %time% Processing %%a && osql -S
mySQLServer -E -n -i %%a -o err\%%a.err && del %%a

10. SETLOCAL
11. SET /a ctr=0
12. for %%a in (*.out) do (SET fn=%%a) & CALL :LOADEM
13. CALL :LOOP
14. ENDLOCAL

15. :LOADEM
16. SET /a ctr+=1
17. IF %ctr% LSS 25 GOTO :DOIT
18. ECHO %time% Processing (and waiting for) %fn%
19. START /min /WAIT c:\loadout3.bat %fn%
20. SET /a ctr=0
21. GOTO :EOF

22. :DOIT
23. ECHO %time% Processing %fn%
24. START /min c:\loadout3.bat %fn%
25. GOTO :EOF

26. :LOOP
27. cls
28. for /l %%a in (1,1,60) do (
29. echo/Waiting 60 Seconds...
30. echo/
31. echo/ ^< %%a ^>
32. ping 127.0.0.1 -n 2 >nul
33. cls
34. )

35. GOTO :TOP

===========================================
 
Steve said:
1. @echo off
2. @title=Inventory Load

3. :TOP
4. cd \loading
5. if not exist err mkdir err
6. ECHO %time% Executing Load Inventory
7. osql -S mySQLServer -E -n -o err\%1.err -Q "EXEC
sqlDB1..spLoadInventory"
8. move c:\out\*.* c:\loading > nul

9.for %%a in (*.log) do echo %time% Processing %%a && osql -S
mySQLServer -E -n -i %%a -o err\%%a.err && del %%a

10. SETLOCAL
11. SET /a ctr=0
12. for %%a in (*.out) do (SET fn=%%a) & CALL :LOADEM
13. CALL :LOOP

Here you *call* Loop and never return !
14. ENDLOCAL

15. :LOADEM
16. SET /a ctr+=1
17. IF %ctr% LSS 25 GOTO :DOIT
18. ECHO %time% Processing (and waiting for) %fn%
19. START /min /WAIT c:\loadout3.bat %fn%
20. SET /a ctr=0
21. GOTO :EOF

22. :DOIT
23. ECHO %time% Processing %fn%
24. START /min c:\loadout3.bat %fn%
25. GOTO :EOF

26. :LOOP
27. cls
28. for /l %%a in (1,1,60) do (
29. echo/Waiting 60 Seconds...
30. echo/
31. echo/ ^< %%a ^>
32. ping 127.0.0.1 -n 2 >nul
33. cls
34. )

35. GOTO :TOP
Somewhere should be a return from :Loop instead you goto :TOP ?
 
I'm having some problems with a recursion error in a batch file. The
error message is "BATCH RECURSION exceeds STACK limits" with an
additional line that indicates "Recursion Count=1265" and "Stack Usage=
90 percent." The batch is supposed to process lots of files (sometimes
a few hundred, sometimes a few thousand) in a particular directory on my
server.

The process moves files from one dir to another, runs a osql command on
files with a .log extension and then, 25 at a time, runs start to call
another external batch file that contains another osql command. The
process runs okay for approximately 7 days but dies with the above error
message. I've included the contents of the batch below. Any
suggestions would be welcome.

=========================================

1. @echo off
2. @title=Inventory Load

3. :TOP
4. cd \loading
5. if not exist err mkdir err
6. ECHO %time% Executing Load Inventory
7. osql -S mySQLServer -E -n -o err\%1.err -Q "EXEC
sqlDB1..spLoadInventory"
8. move c:\out\*.* c:\loading > nul

9.for %%a in (*.log) do echo %time% Processing %%a && osql -S
mySQLServer -E -n -i %%a -o err\%%a.err && del %%a

10. SETLOCAL
11. SET /a ctr=0
12. for %%a in (*.out) do (SET fn=%%a) & CALL :LOADEM
13. CALL :LOOP
14. ENDLOCAL

15. :LOADEM
16. SET /a ctr+=1
17. IF %ctr% LSS 25 GOTO :DOIT
18. ECHO %time% Processing (and waiting for) %fn%
19. START /min /WAIT c:\loadout3.bat %fn%
20. SET /a ctr=0
21. GOTO :EOF

22. :DOIT
23. ECHO %time% Processing %fn%
24. START /min c:\loadout3.bat %fn%
25. GOTO :EOF

26. :LOOP
27. cls
28. for /l %%a in (1,1,60) do (
29. echo/Waiting 60 Seconds...
30. echo/
31. echo/ ^< %%a ^>
32. ping 127.0.0.1 -n 2 >nul
33. cls
34. )

35. GOTO :TOP

===========================================

On the assumption that it is some sort of resource leak in CMD.EXE, I would

Schedule the job to start every day at 00:00:00
have the schedule job kill the process after 23 hours and 59 minutes.


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
By 'return from :Loop", I presume you mean a GOTO :EOF.

I think he also needs to move the GOTO :TOP from the end of the file and
place it right after the CALL :LOOP.

Tom Lavedas
===========
 
Yes, or simply omit line 35.

The goto :TOP belongs between lines 13 and 14.

Thanks for the suggestions. I've made the changes indicated and will now
wait to see what happens...

Steve
 
Back
Top