From f053502116ef4eafc4ab9dd561d1f6e4a9c2108c Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Sun, 27 Oct 2024 23:16:00 -0400 Subject: [PATCH] Use shutil when looking for executables on the host system --- gef.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gef.py b/gef.py index ac9389003..93c1d83d9 100644 --- a/gef.py +++ b/gef.py @@ -1936,13 +1936,11 @@ def gef_pybytes(x: str) -> bytes: @lru_cache() def which(program: str) -> pathlib.Path: """Locate a command on the filesystem.""" - for path in os.environ["PATH"].split(os.pathsep): - dirname = pathlib.Path(path) - fpath = dirname / program - if os.access(fpath, os.X_OK): - return fpath - - raise FileNotFoundError(f"Missing file `{program}`") + path = shutil.which(program) + if path: + return pathlib.Path(path) + else: + raise FileNotFoundError(f"Missing file `{program}`") def style_byte(b: int, color: bool = True) -> str: