One way is to use this older syntax:
%comspec% ... & if errorlevel 1 pause
In this case, a special variant of if
statement is used, one that tests the current errorlevel state.
Another option might be this:
%comspec% ... || pause
The ||
command delimiter is roughly equivalent to & if !errorlevel! neq 0
, i.e. the subsequent command is executed only if the previous one terminated with a non-zero exit code.