Skip to content

Commit

Permalink
handle empty streams in frozen windows version (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl committed Nov 30, 2017
1 parent cf52749 commit eabfd91
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/urh/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from PyQt5.QtGui import QPalette, QIcon, QColor
from PyQt5.QtWidgets import QApplication, QWidget, QStyleFactory


try:
locale.setlocale(locale.LC_ALL, '')
except locale.Error as e:
Expand All @@ -18,7 +19,36 @@
GENERATE_UI = True


def fix_windows_stdout_stderr():
"""
Processes can't write to stdout/stderr on frozen windows apps because they do not exist here
if process tries it anyway we get a nasty dialog window popping up, so we redirect the streams to a dummy
see https://github.com/jopohl/urh/issues/370
"""

if hasattr(sys, "frozen") and sys.platform == "win32":
try:
sys.stdout.write("\n")
sys.stdout.flush()
except:
class DummyStream(object):
def __init__(self): pass

def write(self, data): pass

def read(self, data): pass

def flush(self): pass

def close(self): pass

sys.stdout, sys.stderr, sys.stdin = DummyStream(), DummyStream(), DummyStream()
sys.__stdout__, sys.__stderr__, sys.__stdin__ = DummyStream(), DummyStream(), DummyStream()


def main():
fix_windows_stdout_stderr()

if sys.version_info < (3, 4):
print("You need at least Python 3.4 for this application!")
sys.exit(1)
Expand Down

0 comments on commit eabfd91

Please sign in to comment.