Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch Script - Setup command then change parameters for each call  (Read 6462 times)

0 Members and 1 Guest are viewing this topic.

tgm99

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 10
    Hi,
    I want to setup a batch file that will run a java jar file that requires a number of parameters. The tidiest way (I think) to do this is to setup the command first, then for each call, change the parameters for the specific call. However, since the file runs sequentially, the parameters need to be setup before the command is setup. This means the command needs to be setup multiple times (after each set of parameters is setup/changed). Is there a way to do this that allows me to setup the command without expanding/replacing the parameters until after I setup the parameters? I'm guessing not, but please confirm.

    E.g. Simplified version to explain what I do and what I want. In reality there are many more parameters and many more calls. I use only 2 parameters and 2 calls below to explain.
    :: Start of file
    :: This is how it works now, but I need to set command twice using the same string
    SET "param1=a1"
    SET "param2=b1"
    SET "command=java theJavaApp.jar %param1% %param2%"
    %command%

    SET "param1=a2"
    SET "param2=b2"
    SET "command=java theJavaApp.jar %param1% %param2%"
    %command%

    :: I want to be able to set command just once (at the start) like below
    SET "command=java theJavaApp.jar %param1% %param2%"

    SET "param1=a1"
    SET "param2=b1"
    %command%

    SET "param1=a2"
    SET "param2=b2"
    %command%

    :: End of File

    I tried to set command by escaping the parameters like this...
    SET "command=java theJavaApp.jar %%param1%% %%param2%%"
    :: This sets command to what I want "java theJavaApp.jar %param1% %param2%", but it does not replace the parameters when I call the command. Is there a way to achieve this?
    SET "param1=a2"
    SET "param2=b2"
    %command%

    Thanks