Zend certified PHP/Magento developer

Linux (Ubuntu) – how to evaluate exit code of command after its output has been piped?

In normal command I can execute other commands based on exit code:

command.sh && command_if_OK.sh || command_if_fail.sh

But I would like to pipe output to log file AND then execute commands according to exit code. Something like this, but obviously it will not work, because the exit code will be one of tee, not original command. How to do it?

command.sh | tee -a logfile.txt && execute_if_command_ok.sh || execute_if_command_failed.sh

any advice please?