From 84ac06805f07d6e86c7bb1aa33131dd397552d9b Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Thu, 30 Nov 2017 16:37:40 +0100 Subject: [PATCH] handle empty streams in frozen windows version (#370) --- src/urh/main.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/urh/main.py b/src/urh/main.py index 3b4b117046..b5d4d0cc62 100755 --- a/src/urh/main.py +++ b/src/urh/main.py @@ -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: @@ -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)