Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Each line in input file.txt has two values separated by a space. Currently using:

for /F "tokens=1,2" %%i in (file.txt) do call :setvars %%i %%j

   :setvars
     set %1=%2
     set %3=%4
     set %4=%5

   :eof

First line works perfectly and all other lines return that the syntax is incorrect. What do I need to do to process all of the lines?

share|improve this question
add comment

1 Answer

test.bat:

@echo off
for /f "tokens=* delims= " %%a in (test.txt) do (
    set /a N += 1
    set v!N! = %%a
)

test.txt:

test value
another yes

With these two files, the environment variables are set properly when test.bat is run. This can be verified by using the set command.

set output:

another=yes
test=value
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.