The for
command should give you what you want:
for /f "tokens=1,2*" %%a in ("%*") do echo command -Duser=%%a -Dpwd=%%b %%c
From the help for for
(for /?
):
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k
would parse each line in myfile.txt, ignoring lines that begin with
a semicolon, passing the 2nd and 3rd token from each line to the for
body, with tokens delimited by commas and/or spaces. Notice the for
body statements reference %i to get the 2nd token, %j to get the
3rd token, and %k to get all remaining tokens after the 3rd. For
file names that contain spaces, you need to quote the filenames with
double quotes. In order to use double quotes in this manner, you also
need to use the usebackq option, otherwise the double quotes will be
interpreted as defining a literal string to parse.
So in my solution, %%a
has the value of the first argument passed to the script, %%b
the value of the second argument, and %%c
the remaining arguments.
When I run batch.bat USR PWD -Dargument1=1 -Dargument2=2
from a command prompt I get:
command -Duser=USR -Dpwd=PWD -Dargument1=1 -Dargument2=2
Remove the echo
after the do
to call your command with the arguments.