From 444abd4c86e554a4557e6ba083efc1e26e8cc010 Mon Sep 17 00:00:00 2001 From: michael2to3 Date: Sun, 1 Oct 2023 09:32:39 +0300 Subject: [PATCH] fix(pidcat): handle non-UTF-8 encodings in sys.stdout --- pidcat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pidcat.py b/pidcat.py index 6a23786..6378884 100755 --- a/pidcat.py +++ b/pidcat.py @@ -359,4 +359,7 @@ def tag_in_tags_regex(tag, tags): message = matcher.sub(replace, message) linebuf += indent_wrap(message) - print(linebuf.encode('utf-8')) + if sys.stdout.encoding.upper() not in ['UTF-8', 'UTF8']: + print(linebuf.encode('utf-8')) + else: + print(linebuf)