better way of getting output and return code from subprocesses