Home > Back-end >  Pass arguments with special characters in BATCH
Pass arguments with special characters in BATCH

Time:01-23

I have batch file (for example: test.bat) which takes up some arguments, one is login, and second one is a password. Password contains special characters ( password!?> ) so to prevent from executing special characters i pass it in double quotes ( "password!?>" ), but I need to pass it to next batch which dumb mysql database so password must be without " ", how can I pass my password like a normal string without double quotes without executing this special characters?

CodePudding user response:

The following is a method for safely capturing arguments to a script and using them.

@Echo off

 Rem # input capture method is a modified version of Dave Benhams method:
 Rem # https://www.dostips.com/forum/viewtopic.php?t=4288#p23980

 SETLOCAL EnableDelayedExpansion
 1>"%~f0:Params.dat" <"%~f0:Params.dat" (
  SETLOCAL DisableExtensions
  Set prompt=#
  Echo on
  For %%a in (%%a) do rem . %*.
  Echo off
  ENDLOCAL
  Set /p "Args="
  Set /p "Args="
  Set "Args=!Args:~7,-2!"
 ) || (
  1>&2 Echo(%~nx0 requires an NTFS drive system to function as intended.
  CMD /C Exit -1073741510
 ) || Goto:Eof

Echo(some command !Args:"=!
Pause
  •  Tags:  
  • Related