How to escape special meaning of amperand

Microsoft Windows server 2003 enterprise
July 13, 2010 at 04:32:36
Specs: Windows 2003,
I have a batch file which takes input from user

echo "Password"
set /p PassWord=

If the user enters a password with & . eg. "abc&123"

I get an error as "123" is considered as a seerate command.Can anyone help me for the same ,I dont want the user to enter the escape character "^" i.e "abc^&123".

See More: How to escape special meaning of amperand

Report •

July 13, 2010 at 14:21:02
one way to handle is encapsulate the data in dbl quotes after input, but dbl quotes would not be allowed (bad idea to try and
allow them in any data, imho)
set /p test=test:
set test="%test%"
echo %test:1,-1%
or: alternative way to strip quotes: for %%a in (%test%) do echo %%~a
the other way is to add the escape yourself, in your script (but you would have to render all the other special char.s as escaped also, and < and > don't seem to be escapable.)
set test=test:
set test=%test:&=^^^&%
etc etc for each special character

Report •

July 13, 2010 at 15:31:31

SET /p pwd=""
IF "%pwd%"=="123&abc" (
ECHO Hello
) ELSE (
ECHO Wrong Password

That seems to work fine...

Report •

July 13, 2010 at 18:16:04
why are you doing this using a batch file? Is this batch file going to be distributed to your users? If it is, don't you think they are able to see where you store your password? If this is for a production environment, consider using other safer approach. eg using a web environment.

GNU win32 packages | Gawk

Report •
Related Solutions

Ask Question