diff --git a/openpype/hooks/pre_non_python_host_launch.py b/openpype/hooks/pre_non_python_host_launch.py index 84a19e4101..946fad0546 100644 --- a/openpype/hooks/pre_non_python_host_launch.py +++ b/openpype/hooks/pre_non_python_host_launch.py @@ -1,11 +1,10 @@ import os -import subprocess -import platform from openpype.lib import ( PreLaunchHook, get_openpype_execute_args ) +from openpype.lib.execute import get_non_python_host_kwargs from openpype import PACKAGE_DIR as OPENPYPE_DIR @@ -53,16 +52,6 @@ class NonPythonHostHook(PreLaunchHook): if remainders: self.launch_context.launch_args.extend(remainders) - if platform.system().lower() == "windows": - # expected behavior - openpype_console opens window with logs - # openpype_gui has stdout/stderr available for capturing - if "openpype_gui" in os.environ.get("OPENPYPE_EXECUTABLE"): - self.launch_context.kwargs.update({ - "creationflags": subprocess.CREATE_NO_WINDOW, - "stdout": subprocess.DEVNULL, - "stderr": subprocess.DEVNULL - }) - else: - self.launch_context.kwargs.update({ - "creationflags": subprocess.CREATE_NEW_CONSOLE - }) + self.launch_context.kwargs = \ + get_non_python_host_kwargs(self.launch_context.kwargs) + diff --git a/openpype/hosts/harmony/api/lib.py b/openpype/hosts/harmony/api/lib.py index a70f12a25a..d9222a8b60 100644 --- a/openpype/hosts/harmony/api/lib.py +++ b/openpype/hosts/harmony/api/lib.py @@ -23,7 +23,7 @@ from .server import Server from openpype.tools.stdout_broker.app import StdOutBroker from openpype.tools.utils import host_tools from openpype import style - +from openpype.lib.execute import get_non_python_host_kwargs # Setup logging. log = logging.getLogger(__name__) @@ -315,7 +315,7 @@ def launch_zip_file(filepath): return print("Launching {}".format(scene_path)) - kwargs = _get_kwargs() + kwargs = get_non_python_host_kwargs({}, False) process = subprocess.Popen( [ProcessContext.application_path, scene_path], **kwargs @@ -622,16 +622,3 @@ def find_node_by_name(name, node_type): return None - -def _get_kwargs(): - """Explicitly handle openpype_gui no not show console.""" - kwargs = {} - if platform.system().lower() == "windows": - if "openpype_gui" in os.environ.get("OPENPYPE_EXECUTABLE"): - kwargs.update({ - "creationflags": subprocess.CREATE_NO_WINDOW, - "stdout": subprocess.DEVNULL, - "stderr": subprocess.DEVNULL - }) - print("kwargs:: {}".format(kwargs)) - return kwargs diff --git a/openpype/lib/execute.py b/openpype/lib/execute.py index afde844f2d..703f443047 100644 --- a/openpype/lib/execute.py +++ b/openpype/lib/execute.py @@ -1,6 +1,7 @@ import os import subprocess import distutils.spawn +import platform from .log import PypeLogger as Logger @@ -272,3 +273,36 @@ def get_linux_launcher_args(*args): launch_args.extend(args) return launch_args + + +def get_non_python_host_kwargs(kwargs, allow_console=True): + """Explicit setting of kwargs for Popen for AE/PS/Harmony. + + Expected behavior + - openpype_console opens window with logs + - openpype_gui has stdout/stderr available for capturing + + Args: + kwargs (dict) or None + allow_console (bool): use False for inner Popen opening app itself or + it will open additional console (at least for Harmony) + """ + if kwargs is None: + kwargs = {} + if platform.system().lower() == "windows": + + executable_path = os.environ.get("OPENPYPE_EXECUTABLE") + executable_filename = "" + if executable_path: + executable_filename = os.path.dirname(executable_path) + if "openpype_gui" in executable_filename: + kwargs.update({ + "creationflags": subprocess.CREATE_NO_WINDOW, + "stdout": subprocess.DEVNULL, + "stderr": subprocess.DEVNULL + }) + else: + kwargs.update({ + "creationflags": subprocess.CREATE_NEW_CONSOLE + }) + return kwargs