How to pass more than 9 parameters to batch file

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

    Use %*. Command Line arguments (Parameters)

    People who looking for how to passthrough any number of params to an executable:

    @ECHO OFF
    SET "EXECUTABLE=C:\PATH\TO\MY\EXECUTABLE.EXE"
    CALL %EXECUTABLE% %*
    

    Answering the question (openurl.bat):

    @ECHO OFF
    SETLOCAL EnableDelayedExpansion
    
    SET URL=
    SET /A BASECONCATENATED=0
    FOR %%A IN (%*) DO (
        SET PARAM=%%A
        SET PARAM=!PARAM:"=!
    
        IF !BASECONCATENATED! EQU 0 (
            SET "URL=!URL!!PARAM!^?"
            SET /A BASECONCATENATED=1
        ) ELSE (
            SET "URL=!URL!!PARAM!^&"
        ) 
    )
    
    SET URL=!URL:~0,-1!
    
    CALL "%SYSTEMDRIVE%\Program Files\Internet Explorer\iexplore.exe" "!URL!"
    
    REM EXAMPLE cmd.exe "openurl.bat" http://www.example.com/addPerson.php "firstName=Juan" "lastName=Cerezo" "hobby1=Coding" "hobby2=Learning" "hobby3=Play Videogames"
    

提交回复
热议问题