How to pass more than 9 parameters to batch file

后端 未结 11 1492
花落未央
花落未央 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条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 18:36

    My alternative allows you skip any number of arguments and requires no shifting

    SETLOCAL
      SET /a SKIP=3
      CALL :SkipAndExec SKIP THESE VARS echo numbers: 1 2 3 4 5 6 7 8 9 0 11 12 13 14
    ENDLOCAL
    GOTO:eof
    
    :SkipAndExec
    SETLOCAL
    SET /a n=0
    FOR %arg IN (%*) DO (
      SET /a n=n+1
      IF %n% GT %SKIP% (
        :: here you could compose a string to use later
        SET _CMD_=%_CMD_% %arg%
      )
    )
    :: here you could call another function and pass in %_CMD_%
    CALL %_CMD_%
    GOTO:eof
    

    If you execute that script, it will print:

    numbers: 1 2 3 4 5 6 7 8 9 0 11 12 13 14
    

提交回复
热议问题