How can I pass arguments to a batch file?

后端 未结 18 2143
陌清茗
陌清茗 2020-11-22 02:53

I need to pass an ID and a password to a batch file at the time of running rather than hardcoding them into the file.

Here\'s what the command line looks like:

18条回答
  •  孤街浪徒
    2020-11-22 03:26

    Let's keep this simple.

    Here is the .cmd file.

    @echo off
    rem this file is named echo_3params.cmd
    echo %1
    echo %2
    echo %3
    set v1=%1
    set v2=%2
    set v3=%3
    echo v1 equals %v1%
    echo v2 equals %v2%
    echo v3 equals %v3%
    

    Here are 3 calls from the command line.

    C:\Users\joeco>echo_3params 1abc 2 def  3 ghi
    1abc
    2
    def
    v1 equals 1abc
    v2 equals 2
    v3 equals def
    
    C:\Users\joeco>echo_3params 1abc "2 def"  "3 ghi"
    1abc
    "2 def"
    "3 ghi"
    v1 equals 1abc
    v2 equals "2 def"
    v3 equals "3 ghi"
    
    C:\Users\joeco>echo_3params 1abc '2 def'  "3 ghi"
    1abc
    '2
    def'
    v1 equals 1abc
    v2 equals '2
    v3 equals def'
    
    C:\Users\joeco>
    

提交回复
热议问题