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

StackOverflow https://stackoverflow.com/questions/232651

  •  04-07-2019
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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!

OTHER TIPS

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.

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.

If batch file has unix line endings (line separators) this can sometimes happen.

Just unix2dos it and problem should be solved.

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

I encountered a similar issue just now with a .cmd file and Windows 8. The solution was to change all line endings to CR+LF DOS style. The issue was confusing because the batch file mostly worked and rearranging lines changed the effect.

The .cmd file looked like:

call:function_A "..\..\folderA\"
call:function_B "..\..\folderB\"
call:function_C "..\..\folderC\"
call:function_D "..\..\folderD\"
goto:eof

:function_A
rem do stuff
goto:eof

...etc...

Function C would cause error "The system cannot find the batch label specified". Strangely it could go away by rearranging the calls. Changing line endings from 0x0A to 0x0D0A seems to have fixed it.

Perhaps VonC meant "the batch file must use CRLF line endings".

i had this issue after copying a start command from word and paste it into the command window. There was a option with "-" on front, and thought the looks the same as the DOS "-" it wasn't :) After typing the "-" by myself the issue was solved and the batch worked ... a hard to find issue ....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top