-2

I have gone through many questions, but not able to make my code work. just want to use if/else statement

I have three products i.e. GMAXGateway,PositionMessaging,RensburgGateway for which I need to perform same action, and for rest three same.

I tried if/else/for but of no success

Original code is below

%3\mqsicreatebar.exe -data "%1" -b "%2" -cleanbuild -a %product%

I have tried below, and many other examples given on websites

For %%A IN (GMAXGateway,PositionMessaging,RensburgGateway)DO (%3\mqsicreatebar.exe -data "%1" -b "%2" -cleanbuild -a %product% -l integrationemm commonemm) For %%A IN (OneTISGateway,AccountMessaging,SecurityMessaging)DO (%3\mqsicreatebar.exe -data "%1" -b "%2" -cleanbuild -a %product%)

Was wondering how to fix the same.

Aman
  • 357
  • 2
  • 5
  • 17

1 Answers1

0

Command processor is not tolerant on leaving out spaces or putting round brackets on next line.

Open a command prompt window, execute the command for /? and read the output help, all display pages, not just first one.

@echo off
for %%A in (GMAXGateway PositionMessaging RensburgGateway) do (
    "%~3\mqsicreatebar.exe" -data "%~1" -b "%~2" -cleanbuild -a %%A -l integrationemm commonemm
)
for %%A in (OneTISGateway,AccountMessaging,SecurityMessaging) do "%~3\mqsicreatebar.exe" -data "%~1" -b "%~2" -cleanbuild -a %%A

The product strings can be separated with a space or comma.

There must be a space between ) and do.

( marking begin of body of FOR loop must be on same line as for, loop variable, in, list of strings, and do with a space between do and (.

) marking end of body should be also always on a separate line.

For a single command it is possible to omit ( and ) and write the command on same line after do as done on second FOR loop. But in general the code is better readable when using the syntax as in first FOR loop also for single commands in body of loop.

And of course the loop variable must be used inside body of the loop and not a different variable not defined at all.

Mofi
  • 46,139
  • 17
  • 80
  • 143