One of the first lines in a batch file I have is this:
IF "%FirstServer2%" == "No" goto :SkipSolution
The variable %FirstServer2% is not declared anywhere, so it must be passed to the batch file somehow. So, how can I pass in the value?
One of the first lines in a batch file I have is this:
IF "%FirstServer2%" == "No" goto :SkipSolution
The variable %FirstServer2% is not declared anywhere, so it must be passed to the batch file somehow. So, how can I pass in the value?
set FirstServer2=No
MyBatchFile.cmd
Simply set the environment variable beforehand and start your batch afterwards.
Named parameters are a bit misleading in this case, as FirstServer2
is just a normal environment variable.
I have used a similar technique in a batch I wrote once which was pretty configurable. Depending on whether variables were set or not it assumed some default values or went with already defined ones. This is a pretty useful technique if you want to avoid excessive parsing of parameters passed directly to the batch.
Passed parameters from the command line are referenced by number (%1, %2, etc.)
Anything else with % in front is going to be an environment variable, either set externally or set within the bat or cmd file.