批次:标签长度

时间:2011-09-30 14:34:06

标签: batch-file

我想知道批处理文件中标签的最大长度。

我发现this Microsoft article说明了:

  

MS-DOS仅识别批处理文件标签的前八个字符;后续字符将被忽略。

他们还提供了一个例子:

@echo off
goto latestch
:latestchanges
echo two
:latestch
echo three

应该输出

two
three

而不是

three

但是在我的系统上,我得到了

three

我尝试使用Windows 7(6.1.7600)和WindowsXP(5.1.2600),并在两者上获得相同的结果。

在我看来,没有八个字符限制!
我错过了什么吗?

5 个答案:

答案 0 :(得分:10)

限制为2047和8192,具体取决于您的操作系统。请参阅this KB article

答案 1 :(得分:5)

MS-DOS而非cmd.exe的示例属实。您cmd.exe的版本高于MS-DOS。随意使用任何长度的标签。

根据该文章,此限制适用于:

Microsoft MS-DOS 4.01 Standard Edition
Microsoft MS-DOS 5.0 Standard Edition
Microsoft MS-DOS 5.0a
Microsoft MS-DOS 6.0 Standard Edition
Microsoft MS-DOS 6.2 Standard Edition
Microsoft MS-DOS 6.21 Standard Edition
Microsoft MS-DOS 6.22 Standard Edition

答案 2 :(得分:1)

在Windows 98之后,当Windows离开MS-DOS平台时,我很确定8字符限制消失了。从Windows 2000开始的所有Microsoft操作系统都不再具有限制。我们今天在Windows 7和其他版本中看到的命令窗口是一个在Windows之上运行的应用程序,而不是命令窗口访问Windows下运行的MS-DOS层的旧实现。

答案 3 :(得分:0)

使用GOTO :LABEL的Windows 7 CMD和BAT批处理命令不限于“:”字符后面的8个字符,如原始海报最初记录时直接执行或从另一个批处理文件调用。 / p>

即,

@echo off
SET VARIABLE=2
if %VARIABLE%.==.  GOTO :LABELNUMBERZERO
if %VARIABLE%.==1. GOTO :LABELNUMBERONE
if %VARIABLE%.==2. GOTO :LABELNUMBERTWO
if %VARIABLE%.==3. GOTO :LABELNU
if %VARIABLE%.==4. GOTO :LABELN
GOTO :ENDTHISLONGTHING
:LABELNUMBERZERO
echo your variable was " "
GOTO :ENDTHISLONGTHING
:LABELNUMBERONE
echo your variable was "1"
GOTO :ENDTHISLONGTHING
:LABELNUMBERTWO
echo your variable was "2"
:ENDTHISLONGTHING
:LABELNU
echo your variable was "3"
:ENDTHISLONGTHING
:LABELN
echo your variable was "4"
:ENDTHISLONGTHING

结果是:     你的变量是“2”

如果我set VARIABLE=4结果是:     你的变量是“4”

因此,即使预先在批处理文件中存在较短标签的相同内容,DOS现在也会将同样命名的(起始字符)视为唯一标签。

答案 4 :(得分:0)

Windows cmd.exe支持的标签长度​​最大为128个字符(包括前导冒号)。在128之后的所有字符都将被忽略。

因此,如果两个标签的前128个字符相同,则标签长度500将与标签长度300相匹配。

这是一个演示行为的批处理脚本:

@echo off

call :xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 125
call :xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 126
call :xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 127
call :xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 128
call :xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 129
call :xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 130

exit /b

:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo %1 finds 125
exit /b

:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo %1 finds 126
exit /b

:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo %1 finds 127
exit /b

:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo %1 finds 128
exit /b

:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo %1 finds 129
exit /b

:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo %1 finds 130
exit /b

-输出-

125 finds 125
126 finds 126
127 finds 127
128 finds 128
129 finds 128
130 finds 128