[英]Batch - get parameter that include special characters
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.批处理应该运行一些带有发送到批处理的参数的 .exe。 Test.bat param1 param2 !@#$%^&*()_+
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!
Important points:要点:
Arg1 Arg2 "!@#$%~"^&*()_+"
Arg1 Arg2 "!@#$%~"^&*()_+"
!
!
characters and any character following / between !
!
characters.~
modifier to remove the surrounding doublequotes during assignment of the expanded argument variable.~
修饰符去除周围的双引号。Set^ "Arg3=%~3"
to protect against unbalanced doublequotes.Set^ "Arg3=%~3"
以防止出现不平衡的双引号。@Echo off
Set^ "Arg3=%~3"
IF Defined Arg3 (
Setlocal EnableDelayedExpansion
Echo(!Arg3!
)
Endlocal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.