Apologies if this topic has been discussed before, but I recently tried to write an error subroutine. I invoked it like this:
Code: Select all
call :error "file "%~1" not found " || goto end
This worked just fine… until I passed "/?" as a filename. The program died, displaying the help info for call.

Turns out call splits its parameters into tokens separated by the usual suspects (space, comma, semi-colon, and equals). Double quotes have no special meaning, as far as call is concerned. For example:
Code: Select all
call :mysub "apple banana cherry"
will store <"apple> in %1, <banana> in %2, and <cherry"> in %3.

I suppose I could store the error message in a variable and pass the variable name as a parameter to the subroutine which would use delayed expansion to expand it, but that would be an awful kludge, imho.
So… is there a simpler solution? One that can cope with anything thrown at it, even parameters such as "/?"
TIA!

- SB