Passing argument to DOS script containing a quote

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
HaroldHare
Posts: 1
Joined: 16 Jan 2009 03:33

Passing argument to DOS script containing a quote

#1 Post by HaroldHare » 16 Jan 2009 03:47

I am trying to test LDAP entry and passwords.

The password may contain the quote character.

I am trying to call my .bat file by:

d:\misc>Mytest.bat "Test Person" <password>

My script expects two arguments.. Name and Password.

Let's say that Test Person has the password ABV9"cc1

What must I do to get the DOS command parser to pass ABV9"cc1 as a string argument so that the script can use it????????????????????

I have tried 'ABV9"cc1' and ABV9\"cc1 but always get invalid command syntax.

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#2 Post by jeb » 18 Jan 2009 14:11

Hi Harlod,

simple if you use only one argument like the password.
Then you can use %* for all the input.

But if you use two arguments, like user and pwd, then it becomes complicated.

The first argument is obviously %1, but the SHIFT command fail for %*.
%* reflects always all arguments, not modified by shift.

I suppose the only way is to remove the first argument from the %* by counting the length of %1.

Something like

Code: Select all

@echo off 
setlocal
set user=%1
set "allArgs=%*"
call :stringLen %usr% usrLen
call set pwd=%%allArgs:~%usrLen%%%

echo %pwd%


only a thought
jeb

Post Reply