views:

1157

answers:

5

I have a post-build event that runs some commands for a c# project. The last command would sometimes cause the ERRORLEVEL value not equils to zero and then the build fails.

I want to append an extra line of command to always set the ERRORLEVEL value to zero. What is the most convenient way to do that?

+2  A: 

Seems to do the trick:

ver > nul

Not everything works, and it is not clear why. For example, the following do not:

echo. > nul
cls > nul
binarycoder
I think the reason of why "echo" and "cls" don't work is because they are the shell built-in commands, not real programs.
I'll give you that, but where is ver.exe?
binarycoder
I can't find "ver.exe" or "ver.com" either. I don't know how to explain that.
+3  A: 

I found that "exit 0" looks like a good way to deal with this problem.

+8  A: 

if you use exit /b 0 you can return an errorlevel 0 from within a child batch script without also exiting the parent.

akf
+1  A: 

In a pre- or post-build event, if the return code of an executable is greater than zero, and the call to the executable is not the last line of the pre- or post-build event, a quick way mute it and avoid triggering a check for a non-zero errorlevel is to follow the failing line with a line that explicitly returns zero:

cmd /c "exit /b 0"

This is essentially a generic combination of the previously-mentioned solutions that will work with more than just the last line of a pre- or post-build event.

Jeff
A: 

add ">nul" after each command that's likely to fail - this seems to prevent the build from failing. You can still check the result of the command by examining %errorlevel%. e.g. findstr "foo" c:\temp.txt>nul & if %errorlevel% EQU 0 (echo found it) else (echo didn't find it)

Chiefy