Check for exit status immediately after running command

Just drive-by editing, thought it made more sense to collect the
exit status immediately when the cmd is run to avoid potential
TOCTOU bugs http://en.wikipedia.org/wiki/Time-of-check-to-time-of-use
(although it still doesn't guarantee the elimination)