This isn't so much of a question as a notation of odd behavior. I have always assumed that the batch interpreter interprets multi-line blocks as a single line as follows:
if [%1]==[] (
echo No parameters!
goto :EOF
)
gets interpreted as
if [%1]==[] ( echo No parameters! & goto :EOF)
For this reason, comments in a multi-line block would be a problem:
if [%1]==[] (
rem Handle incorrect call
echo No parameters!
goto :EOF
)
becomes
if [%1]==[] ( rem Handle incorrect call & echo No parameters! & goto :EOF)
which obviously causes the commands after the comment to be treated as a comment. I am pretty sure that this was how things worked in WinNT.
However, this no longer seems to be the case in WinXP, so I have started commenting like I would in any programming language (copiously, that is). So far so good. I use the :: for comments instead of rem because it looks better and because it is a little more efficient, since the processor doesn't have to interpret the line. So now we have
if [%1]==[] (
::Handle incorrect call
echo No parameters!
goto :EOF
)
Everything still works, although if you leave echo on, you can see that the batch processor doesn't even acknowledge the existence of the comment (unlike REMed comments). The problem came up when I happened to put two comments in a row within a multi-line block.
if [%1]==[] (
::Handle incorrect call
::Tell the user, then quit
echo No parameters!
goto :EOF
)
Now I get an obscure message that says
The system cannot find the drive specified.
The batch file still executes correctly, I just see this error message whenever there are two :: comments in a row. Replacing either :: with rem fixes the problem. Placing a command between the comments fixes the problem. Placing an empty line between the comments causes an incorrect syntax error which stops the whole batch file.
This problem is easy enough to work around, and might be commonly known, although I couldn't find any previous questions about it. I guess I'm just posting this as a warning, since it took me an hour or so to figure out what was causing the problem (it was in the middle of a moderately complex batch file). It takes quite a while before you start to think about your comments as a possible cause of a problem, and even then, it took a while before I realized it wasn't the particular text in the comments.
I am curious as to what the batch interpreter is seeing when I do this. If anyone can shed some light on the issue, I would be interested.
Thanks,
Mark