Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pass a comma as an unquoted parameter to a batch script in the windows CMD

1,173 views
Skip to first unread message

jcma...@gmail.com

unread,
Apr 28, 2008, 7:35:23 AM4/28/08
to
I want to pass a comma as an unquoted parameter to a batch script in
the windows CMD processor.

REM
REM testparm.bat:
REM
REM show all command line parameters
echo %*
REM show individual parameters
echo %1 %2 %3 %4 %5
REM end

This is what happens when I pass five parameters (parameter three is a
comma):
C:> testparm.bat now is , the time six
C:>echo now is , the time
now is , the time

C:>REM show individual parameters

C:>echo now is the time
now is the time

C:>REM end

Here you can see that the first echo (all parameters) includes the
comma but the positional parameter is ignored. In fact, there are
only five positional parameters that should be echoed in the second
echo statement but the sixth argument is echoed. I've even tried
attaching the comma to another character but it disappears from the
positional arguments while it always is displayed by the %*

How can I get the comma to be recognized as a parameter?

Ted Davis

unread,
Apr 28, 2008, 9:32:09 AM4/28/08
to
On Mon, 28 Apr 2008 04:35:23 -0700, jcmauroux wrote:

> How can I get the comma to be recognized as a parameter?

You can't - it's a command line delimiter. You *have* to quote it. Same
with spaces, and several other characters that mean something to the
command processor.

--
T.E.D. (tda...@mst.edu)

foxidrive

unread,
Apr 28, 2008, 12:14:07 PM4/28/08
to

If you explain what you need to do then there may be a way to solve the
issue.

Herbert Kleebauer

unread,
Apr 28, 2008, 12:17:31 PM4/28/08
to


@echo off
setlocal
set p=%*
set p=%p:,=^^,%
set n=1
:loop
for /f "tokens=%n%" %%i in ('echo %p%') do set p%n%=%%i
set /a n=n+1
if not %n%==6 goto :loop
echo parameter 1 : %p1%
echo parameter 2 : %p2%
echo parameter 3 : %p3%
echo parameter 4 : %p4%
echo parameter 5 : %p5%

0 new messages