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 to return the error code of a command in a pipe? For example, this one-line batch script foo.exe returns the error code of foo. But this one: foo.exe | tee output.txt always returns the exit code of tee, which is zero.
