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)
Merge pull request #26 from pmarreck/patch-1

Check for exit status immediately after running command