Batch files return the error code of the last command by default.
Is it somehow possible to return the error code of a former command. Most notably, is it possible t
You can solve the problem by creating a wrapper around your command file:
rem wrapper for command file, wrapper.cmd
call foo.exe
echo %errorlevel%
if errorlevel 1 goto...
Then append tee to the wrapper:
wrapper.cmd | tee result.log
Of course this does not exactly the same, e.g. if you want to log in several files in the wrapped file, it is not possible, but in my case it solved the problem.