Reputation: 783
I know there are many similar question but still not able to make it work.
I have a simple batch that accepts several parameters, one of them is a password which may include special characters.
The batch should run some .exe with the parameters that were sent to the batch.
Test.bat param1 param2 !@#$%^&*()_+
How should I handle the parameter with special characters ?
I tried using this code and also escaping the special characters with ^^ ^& etc.
SET PASSWORD=%3
SET "PASSWORD=%3"
setlocal enabledelayedexpansion
SET "PASSWORD=%3"
echo !PASSWORD!
Upvotes: 1
Views: 787
Reputation: 2951
Important points:
Arg1 Arg2 "!@#$%~^&*()_+"
!
characters and any character following / between !
characters.~
modifier to remove the surrounding doublequotes during assignment of the expanded argument variable.@Echo off
Set "Arg3=%~3"
IF Defined Arg3 (
Setlocal EnableDelayedExpansion
Echo(!Arg3!
)
Endlocal
Upvotes: 3