Code: Select all
/SET1 OP1 OP2 /SET2 OP3
Code: Select all
/SET1 "WORD" OP1 OP2
/SET2 "WORD" OP3
and /OP... may or may not contain double quotes and multiple spaces.
This is the code I made to parse the arguments into variables.
Code: Select all
@ECHO OFF
:: Also, This code is a part of and script.
SETLOCAL ENABLEDELAYEDEXPANSION
SET "OP=%~1 "JobName""
IF /I NOT "!OP:~0,4!" == "/Set" (
ECHO Unrecognized option: "%~1"
ENDLOCAL & EXIT /B 1
)
IF NOT [%1] == [] SETLOCAL DISABLEDELAYEDEXPANSION & GOTO ARGLoop
:START
ECHO DONE
PAUSE
EXIT /B
:ARGLoop
SHIFT
IF [%1] ==[] (
PROGRAM %OP% 2> NUL || ECHO Command Failed: "PROGRAM %OP%"
ENDLOCAL & GOTO START
)
SET "ARG=%1"
IF /I "%ARG:~0,4%" == "/Set" (
PROGRAM %OP% 2> NUL || ECHO Command Failed: "PROGRAM %OP%"
SET "OP=%1 "JobName""
) ELSE (SET "OP=%OP% %1")
GOTO ARGLoop
Code: Select all
/SetHttpMethod OPTIONS /SetMaxDownloadTime 10
Code: Select all
/SetHttpMethod "JobName" OPTIONS
/SetMaxDownloadTime "JobName" 10
Code: Select all
/SetCustomHeaders "User-Agent: Opera/9.60 (Windows NT 6.0; U; en) Presto/2.1.1" /SetHttpMethod OPTIONS /SetMaxDownloadTime 10
I can't find a better way to parse arguments into variables without error.
Is there another good way to parse arguments into variables?