In my batch file I want to pass multiple parameters to some other application.
Now I do it
app.exe %1 %2
and it can only pass two parameters, but I want to pass all the parameters that are passed to the batch(I would rather not write %1 %2 %3 %4 ...)
Is there any magic way to do it?
Another way is to use one double quoted parameter. When calling the other application, you just use the
%~N
device on the command line to remove the quotes.If some parameters you intend to pass to the application are themselves double-quoted, those quote chars must be repeated twice.
Here's an illustration script that uses the first parameter as the application's name and the second as a combined parameter list to pass to the application:
Here are examples of calling the script for different cases (pass one parameter or several parameters or quoted parameters).
Pass 1 parameter to the app:
Pass several parameters:
Pass a parameter that includes spaces (and so must be quoted):
A combined example: some parameters are with spaces, others aren't:
You could use the SHIFT prompt and loop through the arguments. Here is a demonstrative example where you would replace the final ECHO prompt with a prompt to load your application.
This may be useful if you need some sort of dynamic parameter counting, or if you want to disallow a certain parameter.
There is a magic way! I knew it, but I could not remember it.
its
%*