How to pass more than 9 parameters to batch file

后端 未结 11 1468
花落未央
花落未央 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:46

    The solution by basin should work. To address the problem with the code in the question: You can't just put multiple commands in a single line and you can't use the shift command in the middle of another command's arguments. Basically you have to split everything up, like shown in the other answer. To make it more concise and readable I would do it like this:

    set "ieargs=http://example.com?firstName=%1^&middleName=%2^&lastName=%3^&country=%4^&address=%5^&address2=%6^&address3=%7^&mobileNo=%8^&landlineNo=%9"
    
    @for /L %%i in (0,1,8) do shift
    set "ieargs=%ieargs%^&emailAddress=%1^&hobby1=%2^&hobby2=%3^&hobby3=%4^&hobby4=%5^&hobby5=%6"
    
    start iexplore %ieargs%
    

    The first nine arguments are saved in the string. Then it loops and shifts nine times, so that %1 will be the thenth argument.

    If you need even more arguments you can just repeat this as often as you need:

    set "ieargs=http://example.com?firstName=%1^&middleName=%2^&lastName=%3^&country=%4^&address=%5^&address2=%6^&address3=%7^&mobileNo=%8^&landlineNo=%9"
    
    @for /L %%i in (0,1,8) do shift
    set "ieargs=%ieargs%^&emailAddress=%1^&hobby1=%2^&hobby2=%3^&hobby3=%4^&hobby4=%5^&hobby5=%6^&hobby6=%7^&hobby7=%8^&hobby8=%9"
    
    @for /L %%i in (0,1,8) do shift
    set "ieargs=%ieargs%^&hobby9=%1^&hobby10=%2^&hobby11=%3^&hobby12=%4"
    
    start iexplore %ieargs%
    

提交回复
热议问题