I have a command (let's call it command) that prints to standard out and will also set ERRORLEVEL based on the success or failure of the execution. I'd like to call command from a batch script that will process command's output, but only if command exited with an ERRORLEVEL of 0 (i.e. success). This would preferably be done without the need for a temporary file or checking the command's output to infer whether it was successful.
I'm able to capture the output of the command using a for statement, but I'm having trouble checking ERRORLEVEL when doing this. I've tried something like:
for /F %%A in ('command') do (
REM The following check does not seem to work
if ERRORLEVEL 1 goto error
REM otherwise, do stuff with %%A
)
I've also tried using %errorlevel% and !errorlevel! (with setlocal enabledelayedexpansion), but neither worked.
IF %ERRORLEVEL% NEQ 0 goto error