How can I pass arguments to a batch file?

后端 未结 18 2169
陌清茗
陌清茗 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:14

    Another useful tip is to use %* to mean "all". For example:

    echo off
    set arg1=%1
    set arg2=%2
    shift
    shift
    fake-command /u %arg1% /p %arg2% %*
    

    When you run:

    test-command admin password foo bar
    

    the above batch file will run:

    fake-command /u admin /p password admin password foo bar
    

    I may have the syntax slightly wrong, but this is the general idea.

提交回复
热议问题