Kurt_Zhu
Kurt_Zhu

Reputation: 47

How to use bat to get values from .ini file where the value contains '='

Using codes like below:

for /f "tokens=1,2 delims==" %%i in (test.ini) do (
  if "%%i"=="mvn_command" set mvn_command=%%j
)

The value I get from such file:

test.ini (has below line as its content)

mvn_command=mvn install -DMAJOR_VERSION=1.0 -Dbuildenv=dev

is:

mvn_command=mvn install -DMAJOR_VERSION

which is not what is expected.

Even put the value in quotes did not work.

Is there any trick to play here as a solution? Or any other way to read the expected value? Thanks a lot.

Upvotes: 0

Views: 176

Answers (1)

MC ND
MC ND

Reputation: 70941

You need to indicate that you want the first token and, not the second token, but the rest of the line

tokens=1,*

that is the first token goes to the first replaceable parameter (%%i in your code) and the rest of the line to the second one (%%j in your code)

Upvotes: 2

Related Questions