1

For my batch script I'm want to know how to use some self defined parameters in my batch script. For example :

MyBatch.bat -env:Test 

or

MyBatch.bat env=Test

I want to know how to parse the value behind the key in my batch script?

wogsland
  • 9,106
  • 19
  • 57
  • 93

1 Answers1

0

To use parameters inside a batch-file, you use variables like %~1 (note the ~ is there to get rid of quotes around a parameter) if you then have a key value pair as parameter, you could do this

@echo off
for /f "tokens=1,2 delims=:=" %%i in ("%~1") do (
  echo %%i %%j
)

Note that = normally counts as a delimiter, causing your batch file to see env=Test as %~1 is env, %~2 is Test. If you want the above solution to work with both, you should use

MyBatch.bat env:Test

and

MyBatch.bat "env=Test"

For more information about arguments, see this

Dennis van Gils
  • 3,487
  • 2
  • 14
  • 35