2

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.

Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61
Eric Bergman
  • 1,453
  • 11
  • 46
  • 84
  • 2
    Possible duplicate of [Echo exact string in windows batch file?](http://stackoverflow.com/questions/9757480/echo-exact-string-in-windows-batch-file) – Eugene Sh. Feb 10 '16 at 22:39
  • Essentially, you're on a wild-goose chase. Since the user can put any characters into the file, you need to deal with all of the possibilities for special characters - no doubt a way could be found to correctly process each one, but consider [`"=%^&*?)~:\/<>,;`] and of course Space. Character-case, too. A nightmare - some other method needed, I'd recommend. – Magoo Feb 10 '16 at 22:51

1 Answers1

1

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.

jeb
  • 78,592
  • 17
  • 171
  • 225