From fb4786e8aa8b557b8d4897f5edd4af21114a3d44 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 6 Apr 2021 10:10:39 +0200 Subject: [PATCH 1/6] launch arguments may be a string --- openpype/lib/applications.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index e043c9d05c..e5bfe679d1 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -804,10 +804,15 @@ class ApplicationLaunchContext: self.log.debug("All prelaunch hook executed. Starting new process.") # Prepare subprocess args - args = self.clear_launch_args(self.launch_args) - self.log.debug( - "Launching \"{}\" with args ({}): {}".format( - self.app_name, len(args), args + args_len_str = "" + if isinstance(self.launch_args, str): + args = self.launch_args + else: + args = self.clear_launch_args(self.launch_args) + args_len_str = " ({})".format(len(args)) + self.log.info( + "Launching \"{}\" with args{}: {}".format( + self.app_name, args_len_str, args ) ) # Run process From bb2a82d8e322c78eab8adccdd4687339f27f239c Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 6 Apr 2021 10:12:11 +0200 Subject: [PATCH 2/6] arguments are not stored as list but as string as it is required for subprocess.Popen --- openpype/hooks/pre_with_windows_shell.py | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/openpype/hooks/pre_with_windows_shell.py b/openpype/hooks/pre_with_windows_shell.py index 5f0f03f13e..fbc9cafae0 100644 --- a/openpype/hooks/pre_with_windows_shell.py +++ b/openpype/hooks/pre_with_windows_shell.py @@ -1,4 +1,5 @@ import os +import subprocess from openpype.lib import PreLaunchHook @@ -15,10 +16,22 @@ class LaunchWithWindowsShell(PreLaunchHook): platforms = ["windows"] def execute(self): - # Get comspec which is cmd.exe in most cases. - comspec = os.environ.get("COMSPEC", "cmd.exe") - # Add comspec to arguments list and add "/k" - new_args = [comspec, "/c"] - new_args.extend(self.launch_context.launch_args) + new_args = [ + # Get comspec which is cmd.exe in most cases. + os.environ.get("COMSPEC", "cmd.exe"), + # NOTE change to "/k" if want to keep console opened + "/c", + # Convert arguments to command line arguments (as string) + "\"{}\"".format( + subprocess.list2cmdline(self.launch_context.launch_args) + ) + ] + # Convert list to string + # WARNING this only works if is used as string + args_string = " ".join(new_args) + self.log.info(( + "Modified launch arguments to be launched with shell \"{}\"." + ).format(args_string)) + # Replace launch args with new one - self.launch_context.launch_args = new_args + self.launch_context.launch_args = args_string From 59a512db43f7ed45242b12764353acc7fb87fb22 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 6 Apr 2021 10:12:22 +0200 Subject: [PATCH 3/6] change creationflags --- openpype/hooks/pre_with_windows_shell.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openpype/hooks/pre_with_windows_shell.py b/openpype/hooks/pre_with_windows_shell.py index fbc9cafae0..a06191ad04 100644 --- a/openpype/hooks/pre_with_windows_shell.py +++ b/openpype/hooks/pre_with_windows_shell.py @@ -35,3 +35,7 @@ class LaunchWithWindowsShell(PreLaunchHook): # Replace launch args with new one self.launch_context.launch_args = args_string + # Change `creationflags` to CREATE_NEW_CONSOLE + self.launch_context.kwargs["creationflags"] = ( + subprocess.CREATE_NEW_CONSOLE + ) From 83f24e491ceeac94ce850f696eeda7dcbf28b233 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 6 Apr 2021 10:12:30 +0200 Subject: [PATCH 4/6] changed order of shell prelaunch hook --- openpype/hooks/pre_with_windows_shell.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openpype/hooks/pre_with_windows_shell.py b/openpype/hooks/pre_with_windows_shell.py index a06191ad04..e26c31532b 100644 --- a/openpype/hooks/pre_with_windows_shell.py +++ b/openpype/hooks/pre_with_windows_shell.py @@ -11,7 +11,8 @@ class LaunchWithWindowsShell(PreLaunchHook): instead. """ - order = 10 + # Should be as last hook becuase must change launch arguments to string + order = 1000 app_groups = ["resolve", "nuke", "nukex", "hiero", "nukestudio"] platforms = ["windows"] From 37db18a6300b4014c300dc378e2422106e006fb5 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 6 Apr 2021 10:13:57 +0200 Subject: [PATCH 5/6] better while loop logic --- openpype/lib/applications.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index e5bfe679d1..6ce2ec297d 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -858,7 +858,10 @@ class ApplicationLaunchContext: Return: list: Unpacked arguments. """ - while True: + if isinstance(args, str): + return args + all_cleared = False + while not all_cleared: all_cleared = True new_args = [] for arg in args: @@ -870,8 +873,6 @@ class ApplicationLaunchContext: new_args.append(arg) args = new_args - if all_cleared: - break return args From 4377dbb02681ccb42628366c16e6c3429d2430f7 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 8 Apr 2021 10:46:01 +0200 Subject: [PATCH 6/6] removed resolve from shell prelaunch hook --- openpype/hooks/pre_with_windows_shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hooks/pre_with_windows_shell.py b/openpype/hooks/pre_with_windows_shell.py index e26c31532b..0c10583b99 100644 --- a/openpype/hooks/pre_with_windows_shell.py +++ b/openpype/hooks/pre_with_windows_shell.py @@ -13,7 +13,7 @@ class LaunchWithWindowsShell(PreLaunchHook): # Should be as last hook becuase must change launch arguments to string order = 1000 - app_groups = ["resolve", "nuke", "nukex", "hiero", "nukestudio"] + app_groups = ["nuke", "nukex", "hiero", "nukestudio"] platforms = ["windows"] def execute(self):