Techinque for loading batch file parameters/settings

This technique allows you to define all of your parameters in a single file and not have to pass them all in on the command line.

This command reads in all of the tokens from the settings file and sets a series of environment variables

for /f "eol=# tokens=1,2 delims==" %%i in (settings.ini) do SET %%i=%%j

The settings file looks like this

# Comment
FirstVariableName=A value

# Comment
AnotherVariableName=A value

Just repeat those blocks. You can then do some validation on the enviroment variables if needs be.

I learnt this technique a little while ago, but I cannot remember where, so I cannot give credit where it is due.

Leave a Reply