Add mock stdout/stderr for console=False case on Windows

PyInstaller provided a NulWriter when running in GUI mode, but stdout/
stderr now default to None with PyOxidizer.

Fixes #1786
This commit is contained in:
Damien Elmes 2022-04-09 16:48:06 +10:00
parent a99253b990
commit 0b2a226dc8

View file

@ -59,8 +59,10 @@ try:
sys.stdout.reconfigure(encoding="utf-8") # type: ignore
sys.stderr.reconfigure(encoding="utf-8") # type: ignore
except AttributeError:
# on Windows without console, NullWriter doesn't support this
pass
if is_win:
# On Windows without console; add a mock writer. The stderr
# writer will be overwritten when ErrorHandler is initialized.
sys.stderr = sys.stdout = open(os.devnull, "w", encoding="utf8")
appVersion = _version
appWebsite = "https://apps.ankiweb.net/"