Fixes #4958 Truncate printed stdout if it contains non-printable characters