简体   繁体   中英

Batch: Set password with special characters to variable

So in batch there are a lot of special characters that are reserved and cause issues if you use them, if I want to set up a password like so:

SET PASSWORD="123%6!@##$^&*_-"

Some of these characters will be stripped after assignment for example the percent '%' character is interpreted as a parameter, is there a way to make batch see that as a string instead of interpreting special characters? no I cannot escape those special characters, this is basically a file that we tell the user to edit teh batch file and set the password.

You could use some magic batch functions to handle with any string, like magic echo .

But I suppose it's better that the user doesn't edit the batch file itself, instead edit a password file, like pwd.txt .
Then you can read this file simply with:

@echo off
setlocal EnableDelayedExpansion
set /p password= < pwd.txt
echo !password!

This read the first line of the file and has no problems with any character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM