What's the maximum number of arguments that I can pass to a batch file?

A. You can pass as many as nine arguments (%1 to %9) to a batch file. For example, if I run test.bat

@rem test.bat
@echo off
echo %1 %2 %3 %4 %5 %6 %7 %8 %9

by typing

C:\>test a b c d e f g h i

the batch file accepts all nine arguments and displays the following output onscreen:

a b c d e f g h i

Argument 0 (%0) is the name of the program or batch file. If you attempt to pass an argument numbered higher than 9 (e.g., 11), the batch file will use only the first digit of the argument number--for example, %11 would become parameter 1 (i.e., %1) and %543 would become parameter 5 (i.e., %5). If I include a few two-digit arguments in test.bat

@rem test.bat
@echo off
echo %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %21 %32

and run the batch file by typing

C:\>test a b c d e f g h i j k l

the batch file displays the following output onscreen:

test a b c d e f g h i a0 b1 c2

Notice that the batch processor amends a number to the parameters that it displays for the two-digit arguments. For example, for parameter 10 (%10), the batch processor used parameter 1 (value a) and added 0 to the end to display a0.

Please also see the FAQ How can I shift down by one all of a batch file's arguments?.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.