I'm using a batch script to invoke the MSVC compiler. I'm trying to handle the output from the compiler line-by-line as it appears (as opposed to waiting for the compiler to finish and handling all the output at once, as for /F
would do). Additionally, I need to know the exit code returned by the compiler.
For the first part, I've found that piping to another batch script works.
(%COMPILER_COMMAND%)|Parser.bat
if errorlevel 1 goto Fail
However, the errorlevel check here is looking at the Parser exit code. The Parser doesn't know the exit code of the compiler so it can't return anything meaningful.
If I try to 'forward' the compilers success/failure the errorlevel check ends up checking the exit code of echo. Again, not very helpful.
(%COMPILER_COMMAND% && echo Success || echo Failure)|Parser.bat
if errorlevel 1 goto Fail
I even tried setting a variable as part of the command but it comes out empty.
(%CC% %SRCPATH% %LN% & set error=!ERRORLEVEL!)|Parser.bat
echo Error %error%
How can I handle output from a command line-by-line and still be able to retrieve the errorlevel?