r12407: Fix returning wrong error codes and better sort out errors and stdout