Missing <CR> after Batch Label Causes Repeat of Last Command (34760)



The information in this article applies to:
    Microsoft MS-DOS operating system 3.3
    Microsoft MS-DOS operating system 3.3a
    Microsoft MS-DOS operating system 4.0
    Microsoft MS-DOS operating system 5.0

This article was previously published under Q34760

SUMMARY

If the last line in a batch file is a label and there is no carriage return character after the label, the command immediately preceding the label will be executed twice.

The workaround for this problem is to include a carriage return at the end of a label.

Microsoft has confirmed this to be a problem in MS-DOS versions 3.3, 3.30a, 4.0, and 5.0. This problem was corrected in MS-DOS version 6.0.

MORE INFORMATION

The following batch file
echo hello <cr>
:label <cr>
<eof>
will produce the following output:
C>echo hello
hello

C>
C>
If the carriage return after the label is omitted, as follows
echo hello <cr>
:label <eof>
the file will produce the following output:
C>echo hello
hello
hello

C>
C>

Modification Type: Major Last Reviewed: 11/25/2003
Keywords: KB34760