There exists different solutions.
Modify the exclamation marks in the password
SET "FTP_PSSWRD=CatDog^!"
But be aware, when there are carets, they need to be escaped, too.
SET "FTP_PSSWRD=CatDog^! and a single ^^ caret"
But if there are only carets and no exclamation marks
SET "FTP_PSSWRD=A single ^ caret"
But now, it only works, if delayed expansion is enabled
Using DisableDelayedExpansion and return from scope
Call your env.cmd file, but use before:
setlocal DisableDelayedExpansion
After the call, you need to leave the setlocal scope and transfer the variable.
See Make an environment variable survive ENDLOCAL
setlocal DisableDelayedExpansion
CALL "_env.cmd"
%endlocal% FTP_PSSWRD
ECHO "!FTP_PSSWRD!"
- Using a macro that creates
%%!
and %%^
for-meta-variables, they expands to !
and ^
independent of the delayed expansion mode
FOR /F "tokens=1 delims== " %%! in ("!=! ^^^!") DO ^
FOR /F %%^^ in ("^ ^^^^%%!=%%!") DO ^
set ^"$lib.macrodefine.free=@FOR /F "tokens=1 delims== " %%%%! in ("%%!=%%! %%^%%^%%^%%!") DO ^
@FOR /F %%%%^^%%^^ in ("%%^ %%^%%^%%^%%^%%^%%!=%%^%%!") DO @"
setlocal EnableDelayedExpansion
call :test
endlocal
setlocal DisableDelayedExpansion
call :test
endlocal
exit /b
:test
%$lib.macrodefine.free% SET "FTP_PSSWRD=CatDog%%!"
set "FTP_PSSWRD"