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?
There is no practical limit to the number of parameters you can pass to a batch file, but you can only address parameter 0 (%0 - The batch file name) through parameter 9 (%9).
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
You simply substitute the parameter for 1 (e.g., %~f2 for the second parameter's fully qualified path name). The %0 parameter in a batch file holds information about the file when it runs and indicates which command extensions you can use with the file (e.g., %~dp0 gives the batch file's drive and path).
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
There is a magic way! I knew it, but I could not remember it.
its %*
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.
@ECHO OFF SET PARAMS= :_PARAMS_LOOP REM There is a trailing space in the next line; it is there for formatting. SET PARAMS=%PARAMS%%1 ECHO %1 SHIFT IF NOT "%1"=="" GOTO _PARAMS_LOOP ECHO %PARAMS% PAUSE
This may be useful if you need some sort of dynamic parameter counting, or if you want to disallow a certain parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With