Get output before receiving return code

Fixes hangs observed with large amounts of output, as it would get into
a dead-lock.