Trying to pass down 24 parameters to Windows batch file (chokes after 9)

I'm using some functionality in SQL Server to build up a call to a Windows batch file, with that call to the batch file intended to pass down a total of 24 parameters.

So the functionality in SQL looks like this :

SET @COMMAND = 'CALL batchtest.bat ' + @PROGRAM_CALLED + ' ' + @JOB_QUEUE + ' ' + @FROMDATE + ' ' + @TODATE + ' ' + @OBJ1 + ' ' + @OBJ2 + ' ' + @OBJ3 + ' ' + @OBJ4 + ' ' + @OBJ5 + ' ' + @OBJ6 + ' ' + @OBJ7 + ' ' + @OBJ8 + ' ' + @OBJ9 + ' ' + @OBJ10 + ' ' + @OBJ11 + ' ' + @OBJ12 + ' ' + @OBJ13 + ' ' + @OBJ14 + ' ' + @OBJ15 + ' ' + @OBJ16 + ' ' + @OBJ17 + ' ' + @OBJ18 + ' ' + @OBJ19 + ' ' + @OBJ20 + ' '


This is how SQL Server constructs the call to the batch file

CALL batchtest.bat TESTPROG JOBQ 20130801 20130831 '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''    

In the batch file, I eventually use rmtcmd to build up a sbmjob command to an IBM AS400 system :

rmtcmd //as400machine "sbmjob cmd(call %1 parm('%3' '%4' %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16 %17 %18 %19 %20 %21 %22 %23 %24)) ...etc...

The problem I'm having is that the Windows batch file does not seem to handle more than 9 parameters.

If I use echo in the batch file (i.e. echo %%1  = (%1) etc ..) to log the imcoming parameters, I see the following :

%1  = (TESTPROG)
%2  = (JOBQ)
%3  = (20130801)
%4  = (20130831)
%5  = ('')
%6  = ('')
%7  = ('')
%8  = ('')
%9  = ('')
%10 = (TESTPROG0)
%11 = (TESTPROG1)
%12 = (TESTPROG2)
%13 = (TESTPROG3)
%14 = (TESTPROG4)
%15 = (TESTPROG5)
%16 = (TESTPROG6)
%17 = (TESTPROG7)
%18 = (TESTPROG8)
%19 = (TESTPROG9)
%20 = (JOBQ0)
%21 = (JOBQ1)
%22 = (JOBQ2)
%23 = (JOBQ3)
%24 = (JOBQ4)

So the echo command shows that parameters %1-%9 are being picked up properly as expected in the batch file, but the next nine (%10 to %19) seem to have the value of %1 (TESTPROG) suffixed by 0, 1, 2, 3 etc, and the next five seem to have the value of %2 (JOBQ) suffixed by 0, 1, 2, 3 etc ...

Any ideas, how I can pick up ALL of the 24 incoming parameters in the Windows batch file so that they can be passed down to my rmtcmd command ?

Thanks

Ray
raymurphyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
You need to do that in a loop using "shift"; use this at the beginning of your script, and you can then address the arguments as %Arg1% to %Arg24% after the ":Done":
@echo off
setlocal enabledelayedexpansion
set /a Index=0
:ArgLoop
if "%~1"=="" goto :Done
set /a Index += 1
set Arg!Index!=%1
shift
goto :ArgLoop
:Done
echo %Index% arguments found:
set Arg

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
raymurphyAuthor Commented:
Just tried that in my batch file, and it worked perfectly, so thanks a lot for such a swift and accurate solution - much appreciated ....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.