If you write
2>nul ( >>test.xlsx (call )) if %errorlevel% == 1 goto end
you get an error. if is not expected
. Two instructions in the same line without separation.
If it is converted into
2>nul ( >>test.xlsx (call )) & if %errorlevel% == 1 goto end
Then the problem is delayed expansion. The %errorlevel%
variable is replaced with its value when the line is parsed and at this time, the first part of has not been executed, so no errorlevel is set.
If you change it to
2>nul ( >>test.xlsx (call ))
if %errorlevel% == 1 goto end
it will work
For a more concise construct, you can try this
(>>test.xlsx call;) 2>nul || goto end
Same function, less code.