I had a similar problem and settled on the following solution as I did not need to detect the exact error code just success or failure.
echo > .failed.tmp
( foo.exe && del .failed.tmp ) | tee foo.log
if exist .failed.tmp (
del .failed.tmp
exit /b 1
) else (
exit /b 0
)