How can I pass arguments to a batch file?

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

    For to use looping get all arguments and in pure batch:

    Obs: For using without: ?*&<>


    @echo off && setlocal EnableDelayedExpansion
    
     for %%Z in (%*)do set "_arg_=%%Z" && set/a "_cnt+=1+0" && (
         call set "_arg_[!_cnt!]=!_arg_!" && for /l %%l in (!_cnt! 1 !_cnt!
         )do echo/ The argument n:%%l is: !_arg_[%%l]!
     )
    
    goto :eof 
    

    Your code is ready to do something with the argument number where it needs, like...

     @echo off && setlocal EnableDelayedExpansion
    
     for %%Z in (%*)do set "_arg_=%%Z" && set/a "_cnt+=1+0" && call set "_arg_[!_cnt!]=!_arg_!"
     
     fake-command /u !_arg_[1]! /p !_arg_[2]! > test-log.txt
     
    

提交回复
热议问题