diff --git a/daemon/core/utils.py b/daemon/core/utils.py index 7a8b42b8..0eb9fef1 100644 --- a/daemon/core/utils.py +++ b/daemon/core/utils.py @@ -13,6 +13,7 @@ import logging.config import os import random import shlex +import shutil import sys from subprocess import PIPE, STDOUT, Popen from typing import ( @@ -151,16 +152,9 @@ def which(command: str, required: bool) -> str: :return: command location or None :raises ValueError: when not found and required """ - found_path = None - for path in os.environ["PATH"].split(os.pathsep): - command_path = os.path.join(path, command) - if os.path.isfile(command_path) and os.access(command_path, os.X_OK): - found_path = command_path - break - + found_path = shutil.which(command) if found_path is None and required: raise ValueError(f"failed to find required executable({command}) in path") - return found_path