A batch script allows you to execute a command with escaped spaces (or any token delimiter) within the name. Note that a name cannot be called with escapes directly because CALL doubles all carets, so the token delimiters are no longer escaped. Instead a variable must be defined and then use CALL %%VAR%%.
The command line does not allow this unless the very first character of the name(or path) is an escaped token delimiter. If the first character is an escaped token delimiter, then any number of escaped token delimiters can appear anywhere else in the name.
I have the same script under two names:
"a b.bat"
" a b.bat"
Code: Select all
executing "%~nx0"
Code: Select all
@echo off
setlocal
set "var=%~1"
<nul set /p "=Command Line NO CALL: "
cmd /c %1
<nul set /p "=Batch File CALL: "
call %%var%%
<nul set /p "=Batch File NO CALL: "
%~1
Code: Select all
>test "a^ b"
Command Line NO CALL: 'a' is not recognized as an internal or external command,
operable program or batch file.
Batch File CALL: executing "a b.bat"
Batch File NO CALL: executing "a b.bat"
>test "^ a^ b"
Command Line NO CALL: executing " a b.bat"
Batch File CALL: executing " a b.bat"
Batch File NO CALL: executing " a b.bat"
>test "^ \x^ y^ ^z\..\..\a^ b"
Command Line NO CALL: executing "a b.bat"
Batch File CALL: executing "a b.bat"
Batch File NO CALL: executing "a b.bat"
>test "x^ \x^ y^ ^z\..\..\a^ b"
Command Line NO CALL: 'x' is not recognized as an internal or external command,
operable program or batch file.
Batch File CALL: executing "a b.bat"
Batch File NO CALL: executing "a b.bat"