[Console] fix and refactor exit code handling
merged branch Tobion/console-exit-code (PR #8080)

This PR was merged into the 2.1 branch.

Discussion
----------

[Console] fix and refactor exit code handling

Split of #8038

Commits
-------

5c317b7 [Console] fix and refactor exit code handling