Skip to content

Commit

Permalink
Windows launcher: provide dummy sys.stderr and sys.stdout
Browse files Browse the repository at this point in the history
Recent versions of PyInstaller do not provide dummy `sys.stderr`
and `sys.stdout` in noconsole/windowed mode anymore. Instead, they
are left at `None`, same as when script is ran using `pythonw.exe`.

Provide dummy file-like objects for `sys.stderr` and `sys.stdout`
to prevent errors in parts of the code that blindly assume that
the streams are available.
  • Loading branch information
rokm committed Mar 3, 2023
1 parent d075ecd commit e1287b6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions exaile_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
import builtins
import msvcrt
import sys
import os
from ctypes import windll


# Provide dummy sys.stdout and sys.stderr, which are None in noconsole/windowed
# mode (launched using pythonw.exe, or PyInstaller build).
if sys.stdout is None:
sys.stdout = open(os.devnull, "w")
if sys.stderr is None:
sys.stderr = open(os.devnull, "w")


__builtin__open = __builtins__.open


Expand Down

0 comments on commit e1287b6

Please sign in to comment.