Running the following minimal example:
(
echo if "%%1" == "" (
echo echo Success ^|^| goto :fail
echo ^) else (
echo echo Failure ^|^| goto :fail
echo ^)
) >"testresult.bat"
call "testresult.bat" "first 1" --flag="other options" --verbose
Results the following as contents of testresult.bat
:
if "%1" == "" (
echo Success || goto :fail
) else (
echo Failure || goto :fail
)
And calling testresult.bat
with the command line arguments "first 1" --flag="other options" --verbose
gives me:
C:\User>test.bat
C:\User>(
echo if "%1" == "" (
echo echo Success || goto :fail
echo ) else (
echo echo Failure || goto :fail
echo )
) 1>"testresult.bat"
C:\User>call "testresult.bat" "first 1" --flag="other options" --verbose
1"" was unexpected at this time.
C:\User>if ""first 1"" == "" (
C:\User>
The error 1"" was unexpected at this time.
is caused because my first arguments has a double quotes.
How can I properly write my if "%1" == ""
to check whether the first argument is empty, regardless it has double quotes or not?