This documentation is archived and is not being maintained.

Return Value of cl.exe

cl.exe returns zero for success (no errors) and non-zero otherwise.

The return value of cl.exe can be useful if you are compiling from a script, or .bat file. You should still plan to capture the output of the compiler, in case there are errors or warnings, so you can resolve them.

The following is a sample .bat file that uses the return value of cl.exe.

echo off
cl /W4 t.cpp
@if ERRORLEVEL == 0 (
   goto good
)

@if ERRORLEVEL != 0 (
   goto bad
)

:good
   echo "clean compile"
   echo %ERRORLEVEL%
   goto end

:bad
   echo "error or warning"
   echo %ERRORLEVEL%
   goto end

:end
Show: