From e0879fd67d642f7e34e4e70ba43979fc1cdb6dd9 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Thu, 16 Feb 2023 17:03:04 +0100 Subject: [PATCH] Pass creation flags on windows in UI executables --- openpype/lib/execute.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/openpype/lib/execute.py b/openpype/lib/execute.py index 39532b7aa5..e60bffbd7a 100644 --- a/openpype/lib/execute.py +++ b/openpype/lib/execute.py @@ -74,18 +74,23 @@ def execute(args, return popen.returncode -def run_subprocess(*args, **kwargs): +def run_subprocess(*args, creationflags=None, **kwargs): """Convenience method for getting output errors for subprocess. Output logged when process finish. Entered arguments and keyword arguments are passed to subprocess Popen. + Set 'creationflags' to '0' (int) if auto-fix for creation of new window + should be ignored. + Args: - *args: Variable length arument list passed to Popen. + *args: Variable length argument list passed to Popen. + creationflags (int): Creation flags for 'subprocess.Popen'. + Differentiate on OS. **kwargs : Arbitrary keyword arguments passed to Popen. Is possible to - pass `logging.Logger` object under "logger" if want to use - different than lib's logger. + pass `logging.Logger` object under "logger" to use custom logger + for output. Returns: str: Full output of subprocess concatenated stdout and stderr. @@ -95,6 +100,21 @@ def run_subprocess(*args, **kwargs): return code. """ + # Modify creation flags on windows to hide console window if in UI mode + if ( + sys.__stdout__ is None + and platform.system().lower() == "windows" + and creationflags is None + ): + creationflags = ( + subprocess.CREATE_NEW_PROCESS_GROUP + | subprocess.DETACHED_PROCESS + ) + + # Ignore if creation flags is set to '0' or 'None' + if creationflags: + kwargs["creationflags"] = creationflags + # Get environents from kwarg or use current process environments if were # not passed. env = kwargs.get("env") or os.environ