NMAKE – Reversing the error code from findstr or grep

If you’re using nmake, you’ll be familiar with this problem… I have logged some process, now I want to check for an error string in the log and terminate my build if it appears, and I don’t want to have to create a .CMD file to do it. The problem is that tools like grep and findstr return a success code when they find something, and that’s the opposite of what we want.

Here’s a quick way to reverse the error code: @findstr “$(TheErrorString)” “$(TheFile)” && exit /b 1 || exit /b 0

This works because. . . && means – Run this command if the previous command completed successfully

|| means – Run this command if the previous command did not complete successfully

Leave a Reply