It has many reasons why the code completly fails with carets.
First the way you try to call your batch will fail.
A caret escapes the next character and is itself removed from the line.
A single caret at a line end escapes the line end (it's called multiline caret), that's the cause why cmd.exe show you the prompt More?
.
This will be true for all odd number of carets.
Sample with seven carets.
length ^^^^^^^
More?
More?
cmd.exe will call the length bat with the following string ^^^<newline>
.
The newline will be split from the %1
parameter, so in %1 is only ^^^
.
But now you this part fails completly
set s=%1
set length=0
As it expands to set s=^^^ set length=0
As the last caret is now a multiline caret it will append set length=0
to the line!
So in the variable s
is now the content ^set length=0
.
This will never work ...
Even in this block the %s:~1%
will be a cause of further problems, as it will also can expand to multiline carets when s
contains carets (when you use 8 carets length ^^^^^^^^
).
if defined s (
set s=%s:~1%
set /A length += 1
goto count
)
For some more explanations about the caret you can read SO:Long commands split over multiple lines in Vista/DOS batch (.bat) file