diff --git a/openpype/lib/__init__.py b/openpype/lib/__init__.py index 5725e1c0e3..1acd07c0ba 100644 --- a/openpype/lib/__init__.py +++ b/openpype/lib/__init__.py @@ -28,6 +28,7 @@ from .execute import ( execute, run_subprocess, split_command_to_list, + path_to_subprocess_arg, CREATE_NO_WINDOW ) from .log import PypeLogger, timeit @@ -173,6 +174,7 @@ __all__ = [ "execute", "run_subprocess", "split_command_to_list", + "path_to_subprocess_arg", "CREATE_NO_WINDOW", "env_value_to_bool", diff --git a/openpype/lib/execute.py b/openpype/lib/execute.py index 2dbee4e674..3e5b6d3853 100644 --- a/openpype/lib/execute.py +++ b/openpype/lib/execute.py @@ -139,6 +139,14 @@ def run_subprocess(*args, **kwargs): return full_output +def path_to_subprocess_arg(path): + """Prepare path for subprocess arguments. + + Returned path can be wrapped with quotes or kept as is. + """ + return subprocess.list2cmdline([path]) + + def split_command_to_list(string_command): """Split string subprocess command to list. @@ -159,6 +167,9 @@ def split_command_to_list(string_command): Returns: list: Command separated into individual arguments. """ + if not string_command: + return [] + kwargs = {} # Use 'posix' argument only on windows if platform.system().lower() == "windows":