How can I pass more than nine parameters to bach file.
I tried another SO question
How do you utilize more than 9 arguments when calling a label in a CMD batch-script?
but not working for me.
I am trying to give the runtime values of a url kept inside batch.
My batch:
start iexplore http://example.com?firstName=%1^&middleName=%2^&lastName=%3^&country=%4^&address=%5^&address2=%6^&address3=%7^&mobileNo=%8^&landlineNo=%9SHIFT SHIFT SHIFT SHIFT SHIFT SHIFT SHIFT SHIFT ^&emailAddress=%1^&hobby1=%2^&hobby2=%3^&hobby3=%4^&hobby4=%5^&hobby5=%6
When using It is taking the previous values of %1, %2, %3,.....etc and the values of 10th,11th,12th.... parameters
Please help !
There is no practical limit to the number of parameters you can pass to a batch file, but you can only address parameter 0 (%0 - The batch file name) through parameter 9 (%9).
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
Here's an even easier solution that assumes you merely want to pass the values to another program. This example allows passing up to 27 parameters to zip...
@echo OFF
set ZipArgs=%1 %2 %3 %4 %5 %6 %7 %8 %9
for /L %%i in (0,1,8) do @shift
set ZipArgs=%ZipArgs% %1 %2 %3 %4 %5 %6 %7 %8 %9
for /L %%i in (0,1,8) do @shift
set ZipArgs=%ZipArgs% %1 %2 %3 %4 %5 %6 %7 %8 %9
"C:\Program Files\WinZip\wzzip.exe" %ZipArgs%
The first line merely turns off echoing each line to the screen. The lines that start with set ZipArgs
build the environment variable ZipArgs
with the next 9 parameters from the command line. The "for" lines use the SHIFT command to discard the first 9 parameters bringing the next 9 "up front". The last line executes zip passing to it the assembled parameter values.
You could complicate things by adding code to check for the number of parameters on the command line and act appropriately, but this does the trick just fine for me.
You can use the shift
command which shift
s the arguments back 1 step, for example %9
would be stored in %8
and %8
would be stored in %7
etc, so if that happened there would be room for a 10th argument in the 9th argument if that makes sense, here is an example:
@echo off
set arg1=%~1
set arg2=%~2
set arg3=%~3
set arg4=%~4
set arg5=%~5
set arg6=%~6
set arg7=%~7
set arg8=%~8
set arg9=%~9
shift
set arg10=%~9
shift
set arg11=%~9
shift
set arg12=%~9
and instead of using %~1
use %arg1%
etc, and to use the 10th, 11th, 12th argument you will use %arg10%
, %arg11%
, %arg12%
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With