Here's one interesting thread. And I tried to play with the two things discussed there.
- You can access labels with special symbols with double expansion.
- Labels that contain
/?
cannot be used becauseGOTO
andCALL
prints their help messages instead of execution.
And here's the result:
@echo off
setlocal enableDelayedExpansion
set "label=/?"
call :%%label%%
echo == Test message to check if the CALL or GOTO ( or neither ) command is executed ==
exit /b 0
:/?
echo == CALL or GOTO has been executed ==
exit /b 0
And the output:
Directs cmd.exe to a labeled line in a batch program.
GOTO label
label Specifies a text string used in the batch program as a label.
You type a label on a line by itself, beginning with a colon.
If Command Extensions are enabled GOTO changes as follows:
GOTO command now accepts a target label of :EOF which transfers control
to the end of the current batch script file. This is an easy way to
exit a batch script file without defining a label. Type CALL /? for a
description of extensions to the CALL command that make this feature
useful.
== Test message to check if the CALL or GOTO ( or neither ) command is executed ==
== Test message to check if the CALL or GOTO ( or neither ) command is executed ==
And the code after the CALL
is executed twice??
EDIT
This is even more unexplainable to me:
@echo off
setlocal enableDelayedExpansion
set "label=/?"
set /a x=1
call :%%label%% >nul
set /a x=x+1
echo ---
echo -%x%-
echo ---
exit /b 0
:/?
echo == CALL or GOTO has been executed ==
echo == first argument : %1 ==
exit /b 0
The output is:
---
-3-
---
The code after the call of the CALL
for sure is executed twice, but the output of the first run can be redirected in the same line?