How to pass more than 9 parameters to batch file

后端 未结 11 1473
花落未央
花落未央 2020-12-17 18:08

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?

11条回答
  •  Happy的楠姐
    2020-12-17 19:01

    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.

提交回复
热议问题