Skip to content

Commit

Permalink
Use shutil when looking for executables on the host system
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Oct 28, 2024
1 parent ba70548 commit f053502
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f053502

Please sign in to comment.