【发布时间】:2015-08-13 11:33:02
【问题描述】:
Here's one interesting thread。我试着玩弄那里讨论的两件事。
- 您可以通过双扩展访问带有特殊符号的标签。
- 不能使用包含
/?的标签,因为GOTO和CALL会打印它们的帮助消息而不是执行。
结果如下:
@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
还有输出:
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 ==
而CALL之后的代码执行了两次??
编辑
这对我来说更无法解释:
@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
输出是:
---
-3-
---
CALL调用后的代码肯定执行了两次,但是第一次运行的输出可以重定向到同一行吗?
【问题讨论】:
-
如果你在
call之后添加一个& pause,它会回显所有内容一次,暂停然后回显它之后 暂停!
标签: batch-file cmd