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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With