Wednesday, November 30, 2011

Inputs and Conditional Processing in Batch File

To get input from the console in a batch file and assign it to a variable  the following syntax works very well.

set /p name=Debug Y/N?

Then you can Echo %name% to print the contents of that variable.

To conditionally check for the content of that variable

IF "%name%" == "y" (other dos commands go here...) Without the enclosing braces :-)

I found it particularly usefull to start my jboss with some agents disabled conditionally based on what options I choose, that way I can still play around with multiple agents and debugging options without having to maintain multiple copied of the run.bat files, which is messy !!!