Solved Maximum setlocal recursion level reached?

June 22, 2014 at 12:53:59
Specs: Windows 64
I have a big batch file where Im using setlocal ENABLEDELAYEDEXPANSION several times. Im wondering if typing it once is enough or does it have to be typed every single time im setting some variables. Is this why Im also getting the "maximum setlocal recursion level reached" message?

See More: Maximum setlocal recursion level reached?

Report •

June 22, 2014 at 22:09:51
✔ Best Answer
It depends on what you're trying to do, but usually, you do not need to specify this instruction more than once. Parent variables values are always passed down to the child (called) script, but "setlocal" keeps them from being passed back up when the child script ends. This also applies to subroutines within a script. If you use a circular (self-invoking) call, and the call uses setlocal, you can easily exceed the stack limit and get this error.

message edited by nbrane

Report •

June 23, 2014 at 07:47:54
It could be argued that SETLOCAL doesn't need to be used at all, unless you need delayed expansion.

Anyways, your error message is because you keep calling SETLOCAL without a corresponding ENDLOCAL. This happens either because you're calling yourself recursively (typically because your script is named the same as some command), or because you never call ENDLOCAL at the end of your functions.

And SETLOCAL should only be used when you want to modify CMD's behavior for your script, or when you risk overwriting a variable whose value you want to save.

How To Ask Questions The Smart Way

Report •

Related Solutions

Ask Question