Page 1 of 1

Weird behavior with CALL (function)

Posted: 20 Jun 2024 02:28
by Ra0
Hi,

I have written this little script and its behavior is driving me mad.

Shortly stated, it calls the same function several consecutive times... and then starts the.. magic ? :lol:
  • up to 35 consecutive CALLs, it works as I would expect
  • if i add a 36th CALL, then it raises error about missing label. Like The system cannot find the batch label specified...
  • if I comment this 36th CALL, then it runs fine... except that some CALLs are ignored, jumped !
  • if I add a hundred more consecutive CALLS, then it runs fine. Even too much: I can see several hundreds if not thousands calls to the function, way more than there is in the script.
    And moreover, every now and then, I can see the error message about missing label... for this same function. And on next CALL it is back again.
IMHO, it looks like at exit of a routine call, the script go back to the instruction that follows the CALL. Well, in theory. Or most of the time. :lol:
Or maybe I have written a wild special character, that would explain this behavior, but I don't see it.

Is this something already mentioned ? Known limitation ? Bug ?

Find my script below, with the 35 CALLs that works fine. Try to add more, and tell me if you experience the same than me...
I run W11 Enterprise - 23H2 (22631.3737).

Code: Select all

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL EnableDelayedExpansion

SET "__DBG=OK"

SET "list="

CALL :__add_item 001
CALL :__add_item 002
CALL :__add_item 003
CALL :__add_item 004
CALL :__add_item 005
CALL :__add_item 006
CALL :__add_item 007
CALL :__add_item 008
CALL :__add_item 009
CALL :__add_item 010
CALL :__add_item 011
CALL :__add_item 012
CALL :__add_item 013
CALL :__add_item 014
CALL :__add_item 015
CALL :__add_item 016
CALL :__add_item 017
CALL :__add_item 018
CALL :__add_item 019
CALL :__add_item 020
CALL :__add_item 021
CALL :__add_item 022
CALL :__add_item 023
CALL :__add_item 024
CALL :__add_item 025
CALL :__add_item 026
CALL :__add_item 027
CALL :__add_item 028
CALL :__add_item 029
CALL :__add_item 030
CALL :__add_item 031
CALL :__add_item 032
CALL :__add_item 033
CALL :__add_item 034
CALL :__add_item 035


:loopscan
call :__print_dbg Processing list %list%
for %%i in ( %list% ) do (
  call :__print_dbg Reading item %%i
)
TIMEOUT 20 /nobreak
GOTO loopscan

EXIT /B

:__print_dbg
IF DEFINED __DBG echo DEBUG %*
goto :eof

:__add_item
call :__print_dbg Adding item %~1
set "list=%list% %~1"
goto :eof

Re: Weird behavior with CALL (function)

Posted: 20 Jun 2024 14:03
by Aacini
Your script run as it should with an additional CALL :__add_item 036 added:

Code: Select all

. . . . .
DEBUG Adding item 034
DEBUG Adding item 035
DEBUG Adding item 036
DEBUG Processing list  001 002 003 004 005 006 007 008 009 010 011 012 013 014 0
15 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 0
35 036
DEBUG Reading item 001
DEBUG Reading item 002
DEBUG Reading item 003
. . . . .
Perhaps you should post the script that causes the error in your computer, not the one that runs fine...

Antonio

Re: Weird behavior with CALL (function)

Posted: 21 Jun 2024 08:47
by jeb
Hi,

my first guess is: You use LF as line ending instead of CRLF.
This causes such suspicious behavior.

jeb

Re: Weird behavior with CALL (function)

Posted: 24 Jun 2024 01:24
by miskox
I can confirm that jeb is right. If file is in Unix format it stops working.

Good catch Jeb!

Saso