From 08b78d7284d4937615d213bafa64d2f641d4dffe Mon Sep 17 00:00:00 2001 From: Rob Hagemans Date: Wed, 3 Aug 2022 21:42:31 +0100 Subject: [PATCH] fix script entry guard - ignore errors if stdio does not exist --- pcbasic/compat/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pcbasic/compat/__init__.py b/pcbasic/compat/__init__.py index ca065245e..60e43eff1 100644 --- a/pcbasic/compat/__init__.py +++ b/pcbasic/compat/__init__.py @@ -21,7 +21,7 @@ # not available in Python <= 3.6 try: - import importlib_resources as resources + import importlib_resources as resources except ImportError: # pragma: no cover from importlib import resources @@ -121,6 +121,12 @@ def script_entry_point_guard(): except Exception: exit_code = True if exit_code: - os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno()) - os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stderr.fileno()) + try: + os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno()) + except Exception: + pass + try: + os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stderr.fileno()) + except Exception: + pass sys.exit(exit_code)