views:

3150

answers:

4

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

The system cannot find the batch label specified name_of_label

Of course label existed. What causes this error?

+3  A: 

If batch file has unix line ends this can sometimes happen.

Just unix2dos it and problem should be solved.

Slimak
+4  A: 

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 and Batch-as-batch-can!

VonC
I know you have answered your own question, but that way, you have an answer to select, since you can not select your own ;)
VonC
Had this issue with the ant batch file shipped with eclipse and being called from MSVC - changing line endings all fixed, thankyou.
Greg Domjan
+1  A: 

You should also make sure that when calling other scripts you use CALL, instead of calling them in the caller's environment.

A: 

Here is the issue and how to fix it. The issue is a bug or a feature in DOS batch cmd program. First the clear problem statement. If you have a DOS batch file with target labels like, ":dothis", and at the end of the label you do not have space then the batch file will not work if the line ending are UNIX line endings. This means you have to run unix2dos on the file before you can use it.

The root cause is the DOS command line processor, (shell program), takes the UNIX end-of-line character as part of the label. Since the go to part never uses this as the label, it is never found since such a label truly does not exist. The solution is to put an extra space at the end of each target label, or even better every line. Now UNIX end of lines do not come to play since the space acts as the separator and it all works.

Masoud Kermani