OK, this is my first post, so I figure I need to explain a bit what I intend this blog is about. Batch. That's what I intend to write. Specifically, tips, tricks and pitfalls of windows batch file.
Now that we have that out of the way, let's take a look at the first of such batch quirk.
When you are using pipes to do some chained processing, just remember that the exit code of the last command in the pipe is the one that prevails.
I've seen this bitten a lot of people:
test.bat ¦ tee.exe outputfile.log
exit /b %errorlevel%
The intention here is to exit with whatever the exit code of test.bat is, when in fact you're capturing exit code of tee.exe, which will most likely be zero.
You'll then end up masking the test.bat exit code. If this is in some pre-checkin test script, that usually ends up with bad codes sneaking in.
So save yourself some time, and output to a file instead, and post process the output.
test.bat > outputfile.log
set EXITCODE =%errorlevel%
This captures your intent just the same (well, almost the same).