为什么“系统找不到指定的批次标签"?即使标签存在也会抛出? [英] Why "The system cannot find the batch label specified" is thrown even if label exists?

查看:61
本文介绍了为什么“系统找不到指定的批次标签"?即使标签存在也会抛出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows XP 中运行批处理文件时,我发现随机出现的错误消息:

While running a batch file in Windows XP I have found randomly occurring error message:

系统找不到指定name_of_label的批次标签

The system cannot find the batch label specified name_of_label

当然标签存在.导致此错误的原因是什么?

Of course label existed. What causes this error?

推荐答案

实际上,你需要两个条件才能做到这一点:

Actually, you need 2 conditions for this to happen:

  • 批处理文件不得使用 CRLF 行尾
  • 您跳转到的标签必须跨越一个块边界(而不是 :end 标签,它只是脚本结尾的快捷方式)

看.系统找不到指定批次标签(由和 Batch-as-batch-can!

David A. Gray 提到了 在评论中看到(在 Windows 10 上)什么 Marshalanswer 出现在 2014 年(大概在 Windows 7 或 8 上):一个脚本/批处理程序(.bat.cmd)在没有 CALL 会触发 eol 转换.

David A. Gray mentions in the comments seeing (on Windows 10) what Marshal's answer showed in 2014 (presumably on Windows 7 or 8): a script/batch program (.bat or .cmd) executed without CALL would trigger an eol conversion.

在过去的 35 年里,我编写了数百个批处理脚本,唯一一次遇到找不到标签的问题是当文件的换行符从 Windows (CR/LF) 转换时,对 Unix (LF) 有效,但无效.

I've written hundreds of batch scripts over the last 35 years, and the only time I've ever had an issue with labels not being found was when the file's line breaks got converted from Windows (CR/LF), which works, to Unix (LF), which doesn't.


二月2020 年,kinar 增加了 在评论中:

刚在Win7机器上遇到这个问题.
事实证明,如果系统上不存在该文件,则在尝试调用另一个 .bat 文件时也会生成此错误.
就我而言,我试图在未安装 VS 的系统上调用 Visual Studio vcvarsall.bat 文件.

Just encountered this issue on a Win7 machine.
Turns out this error can also be generated when trying to CALL another .bat file if that file doesn't exist on the system.
In my case, I was trying to call the Visual Studio vcvarsall.bat file on a system without VS installed.

参见 jeb回答更多:这是一个未定义标签的情况.

See jeb's answer for more: it was a case of an undefined label.

注意:在 Git 存储库中,我建议使用带有指令的 .gitattributes 文件:

Note: in a Git repository, I would recommend a .gitattributes file with the directive:

*.bat   text eol=crlf

这篇关于为什么“系统找不到指定的批次标签"?即使标签存在也会抛出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆