Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are named parameters passed to a batch file?

Tags:

batch-file

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?

like image 678
Jim Avatar asked Apr 16 '09 18:04

Jim


1 Answers

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.

like image 129
Joey Avatar answered Nov 15 '22 13:11

Joey