Windows 批处理文件 - 系统找不到指定的批处理标签 [英] Windows batch file - The system cannot find the batch label specified

查看:318
本文介绍了Windows 批处理文件 - 系统找不到指定的批处理标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Windows 批处理文件和标签时遇到问题.我不断收到此错误:

I'm having a problem with a Windows batch file and labels. I keep getting this error:

系统找不到批次标签指定

The system cannot find the batch label specified

我的尝试

  • 两台电脑;一台 Windows XP 和一台 2003 服务器.
  • 确保它被编码为 ASCII
  • 编辑了行继续符的十六进制代码.尝试用 CR 、 LF 和 CRLF 依次替换 all .所有组合都给我同样的错误.
  • 尝试在标签前插入额外的字符,使标签超过 512 个字符.
  • 代码如下:

    cls
    @echo off
    SET zip=7za a dependencies.7z
    call:dozip "c:	empdir.txt"
    
    pause
    goto exit
    
    :dozip
      echo Testing 1.2.3...
      %zip% %1
    goto:eof
    :exit
    

    这是带有 CRLF (0d 0a) 的十六进制.

    Here's the hex with CRLF (0d 0a).

    63 6c 73 0d 0a 53 45 54 20 7a 69 70 3d 37 7a 61 20 61 20 64 65 70 65 6e 64 65 6e 63 69 65 73 2e 37 7a 0d 0a 63 61 6c 6c 3a 64 6f 7a 69 70 20 22 63 3a 5c 74 65 6d 70 5c 64 69 72 2e 74 78 74 22 0d 0a 0d 0a 70 61 75 73 65 0d 0a 67 6f 74 6f 20 65 78 69 74 0d 0a 0d 0a 3a 64 6f 7a 69 70 0d 0a 20 20 65 63 68 6f 20 54 65 73 74 69 6e 67 20 31 2e 32 2e 33 2e 2e 2e 0d 0a 20 20 25 7a 69 70 25 20 25 31 0d 0a 67 6f 74 6f 3a 65 6f 66 0d 0a 3a 65 78 69 74
    

    这是控制台的输出(当我删除@echo off 时):

    Here's the console's output (when I remove @echo off):

    C:>SET zip=7za a dependencies.7z
    
    C:>call:dozip "c:	empdir.txt"
    
    C:>echo Testing 1.2.3...
    Testing 1.2.3...
    
    C:>7za a dependencies.7z "c:	empdir.txt"
    The system cannot find the batch label specified - dozip
    
    C:>pause
    Press any key to continue . . .
    

    它实际上从未创建过 7zip 文件,所以我想我可以假设它在这一行崩溃了;

    It never actually creates the 7zip file, so I think I can assume that its crashing on this line;

    7za a dependencies.7z "c:	empdir.txt"
    

    如果我从命令提示符单独运行该行,它可以正常工作并创建依赖项.7z,所以我认为它不一定是 7za.exe 的问题.

    If I run that line by itself from a command prompt, it works fine and creates the dependencies.7z, so I don't think its necessarily a problem with 7za.exe.

    我已经阅读了这个 stackoverflow 问题:stackoverflow.com/questions/232651/why-the-system-cannot-find-the-batch-label-specified-is-thrown-even-if-label-ex

    I've already read this stackoverflow question: stackoverflow.com/questions/232651/why-the-system-cannot-find-the-batch-label-specified-is-thrown-even-if-label-ex

    以及那个帖子的链接;help.wugnet.com/windows/system-find-batch-label-ftopict615555.html

    and the link from that post; help.wugnet.com/windows/system-find-batch-label-ftopict615555.html

    所以,我找到了问题所在.

    So, I found the problem guys.

    我使用了一种我常用的技术,我只能将其描述为代理"批处理文件.我有一个名为 c:scripts 的文件夹,我在其中放置了几个 bat 文件以定位常用的 exe.这使我的 PATH 变量免于使用我的所有命令行工具变得绝对庞大.这样我只需要将 c:scripts 添加到我的 PATH 中,并在需要时创建一个代理批处理文件.

    I was using a technique I commonly use that I could only really describe as "proxy" batch files. I have a folder called c:scripts, and I put several bat files in there to target commonly used exes. This saves my PATH variable from becoming absolutely massive with all of my command line tools. This way I only need to add c:scripts to my PATH, and create a proxy batch file when I need something.

    我在 c:scripts 中有 7za.bat,只包含这个;

    I had 7za.bat in c:scripts, containing only this;

    @echo off
    "C:Program Files7-zip7za.exe" %*
    

    我把我的脚本改成了这个;

    I changed my script to this;

    SET zip="c:program files7-zip7za.exe" a dependencies.7z
    

    而不是这个;

    SET zip=7za a dependencies.7z
    

    并且它完美地工作.

    避免从批处理文件中调用其他批处理文件.如果这样做,您需要在它们前面加上call".

    Avoid calling other batch files from within a batch file. If you do, you will need to prefix them with "call".

    推荐答案

    我要指出的是测试 1.2.3..."和按任意键继续..."行表示执行已成功转到 :dozip 标签,然后成功返回给调用者.

    I would point out that the "Testing 1.2.3..." and "Press any key to continue . . ." lines indicate that execution has successfully gone to the :dozip label and then successfully returned to the caller.

    7za"可执行文件实际上是批处理文件吗?如果我修改我的测试脚本以使帮助程序成为批处理文件,则会出现相同的错误.修复方法是调用 %zip% %1"

    Is the "7za" executable actually a batch file? If I modify my test script to have the helper be a batch file, I get the same error. The fix is to do 'call %zip% %1'

    这篇关于Windows 批处理文件 - 系统找不到指定的批处理标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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