[Console] fix and refactor exit code handling

Split of #8038