Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "The system cannot find the batch label specified" is thrown even if label exists?

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

The system cannot find the batch label specified name_of_label

Of course label existed. What causes this error?

like image 764
Slimak Avatar asked Oct 24 '08 06:10

Slimak


People also ask

What does %% mean in batch script?

Use a single percent sign ( % ) to carry out the for command at the command prompt. Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> )

What is label in batch script?

Labels in Batch Files. Labels normally mark the beginning of a code block that is the target of a GOTO instruction, but they can also be used for comments. Labels begin with ':' and contain up to eight characters - anything beyond the first eight will be ignored, both in the label and in the GOTO command.


2 Answers

Actually, you need 2 conditions for this to happen:

  • the batch file must not use CRLF line endings
  • the label you jump to must span a block boundary (as opposed to and :end label wich is just a shortcut to the end of your script)

See. The system cannot find the batch label specified (by and Batch-as-batch-can!

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.

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.


Feb. 2020, kinar adds in the comments:

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.

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


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

*.bat   text eol=crlf 
like image 200
VonC Avatar answered Oct 24 '22 18:10

VonC


I have got the same issue before. However, the root cause was not CRLF at all. It was because in the script I executed an external program such as Ant, but did not put a CALL before Ant. So, make sure you CALL every external program used in your batch script.

like image 31
Marshal Avatar answered Oct 24 '22 18:10

Marshal