while refactoring my macro library, I found an unknown behaviour of the CALL/return file logic.
It fails when in the called batch file path at least one question mark or asterix is embedded.
It seems a little bit related to the (goto) 2> nul glitch.
First a sample, showing the normal behaviour with calling just labels.
callTest1.bat
Code: Select all
@echo off
echo [%0]: Before calling
call :func1
echo [%0]: After calling
exit /b
:func1
echo ..[%0]: Before calling
call :func2
echo ..[%0]: After calling
exit /b
:func2
echo ....[%0]: Before calling
call :func3
echo ....[%0]: After calling
exit /b
:func3
echo ......[%0]: Just return
exit /b
callTest2.batoutput wrote:[callTest1.bat]: Before calling
..[:func1]: Before calling
....[:func2]: Before calling
......[:func3]: Just return
....[:func2]: After calling
..[:func1]: After calling
[callTest1.bat]: After calling
Now the same with a trampoline function, that is more a less calling another batch file with an embedded label
The label itself has no special meaning for the CALL command, but it's parsed in the other batch file in the first lines.
For better visibility and for simpler parsing, I chose to enclose the label into colons, but you could use also other characters for that
Code: Select all
@echo off
REM *** Trampoline jump for function calls of the form ex. "C:\:label:\..\temp\thisBatchFile.cmd"
FOR /F "tokens=3 delims=:" %%L in ("%~0") DO goto :%%L
echo [%0]: Before calling
call %~d0\:func1:\..%~pnx0
echo [%0]: After calling
exit /b
:func1
echo ..[%0]: Before calling
call %~d0\:func2:\..%~pnx0
echo ..[%0]: After calling
exit /b
:func2
echo ....[%0]: Before calling
call %~d0\:func3:\..%~pnx0
echo ....[%0]: After calling
exit /b
:func3
echo ......[%0]: Just return
exit /b
output wrote:[CallTest2.bat]: Before calling
..[c:\:func1:\..\temp\CallTest2.bat]: Before calling
....[c:\:func2:\..\temp\CallTest2.bat]: Before calling
......[c:\:func3:\..\temp\CallTest2.bat]: Just return
....[c:\:func2:\..\temp\CallTest2.bat]: After calling
..[c:\:func1:\..\temp\CallTest2.bat]: After calling
[CallTest2.bat]: After calling
CallTest3.bat
Only a small harmless change at "C\:func3:?\.."
Code: Select all
@echo off
REM *** Trampoline jump for function calls of the form ex. "C:\:label:\..\temp\thisBatchFile.cmd"
FOR /F "tokens=3 delims=:" %%L in ("%~0") DO goto :%%L
echo [%0]: Before calling
call %~d0\:func1:\..%~pnx0
echo [%0]: After calling
exit /b
:func1
echo ..[%0]: Before calling
call %~d0\:func2:\..%~pnx0
echo ..[%0]: After calling
exit /b
:func2
echo ....[%0]: Before calling
call %~d0\:func3:?\..%~pnx0
echo ....[%0]: After calling
exit /b
:func3
echo ......[%0]: Just return
exit /b
The return from :func3 returns directly to :func1, somewhere the return to :func2 is lostOutput wrote:[CallTest3.bat]: Before calling
..[c:\:func1:\..\temp\CallTest3.bat]: Before calling
....[c:\:func2:\..\temp\CallTest3.bat]: Before calling
......[c:\:func3:?\..\temp\CallTest3.bat]: Just return
..[c:\:func1:\..\temp\CallTest3.bat]: After calling
[CallTest3.bat]: After calling
This behaviour is the same as a block with the (goto) glitch
Code: Select all
:func3
(
(goto) > nul
echo ......[%0]: Just return
exit /b
)
I found that the asterix * and the question mark activates the behaviour, but I didn't find any other chararcters now.
jeb