Reading values ​​from a file and assigning it to a variable in batch mode script

I want to read a file that contains the value of some variables that are used in my batch script. I created a properties file with the format

key=key_value
key=key_value

Now I want to set the name of the environment variable as a key and its value as key_value How can I assign?

I read the file, but cannot separate the line "key = key_value" to two lines. Thanks in advance.

+3
source share
1 answer

With the FOR command, you can turn your key / value file from this

KEY1=value
KEY2=value

in that

SET KEY1=value
SET KEY2=value

. , , , .

@echo off
echo rem generated from keyvalue.txt > keyvalue.bat
for /F "tokens=*" %%I in (keyvalue.txt) do @echo set %%I >> keyvalue.bat

call keyvalue.bat

.bat- , key/value keyvalue.txt , = .

+2

Source: https://habr.com/ru/post/1732809/


All Articles