As long as all of the batch parameters are supposed to be passed to your program, then you can simply call your batch with the parameters as you have specified them, and use the following within your batch script.
program.exe %*
The problem becomes much more complicated if you only want to pass some of the batch parameters to the called program.
Unfortunately there is no method to escape quotes within a quoted string. It is also impossible to escape parameter delimiters. So it is impossible to simultaneously embed both spaces and quotes within a single batch parameter.
The SHIFT command can strip off leading parameters, but %*
always expands to the original parameter list; it ignores prior SHIFT operations.
The FOR /F does not ignore quoted delimiters, so it doesn't help.
The simple FOR can properly parse quoted parameter lists, but it expands *
and ?
characters using the file system. That can be a problem.
The only thing left to do is to use a GOTO loop combined with SHIFT to build a string containing your desired parameters.
Suppose the first 3 parameters are strictly for the batch file, and the remaining parameters are to be passed to the called program.
@echo off
setlocal
set "args="
:buildProgramArgs
if [%4]==[] goto :argsComplete
set args=%args% %4
shift /4
goto :buildProgramArgs
:argsComplete
program.exe %args%
::args %1 %2 and %3 are still available for batch use