Skip to content

proposal: os/exec: Provide generalized version of exec.LookPath #59753

@oakad

Description

@oakad

Deciding, whether a particular file can be executed is a surprisingly convoluted problem, as evident from the implementation of exec.LookPath feature. In some cases, particularly when working on various tooling, we want to locate an executable not on the default system path, but elsewhere. Even more so, there may exist several executables, of which some may be preferred over others, due to version and other such considerations.

Therefore, I would like to propose to leverage the platform specific mechanics of exec.LookPath via a companion function:

func FindExecutable(exeName string, possibleLocations []string) (found []string)

The proposed function will do almost exactly the same thing as LookPath, but will take a list of directories as an additional argument (as opposed to predefined list in $PATH) and will return all the results instead of just the first encountered.

Implementing such a feature in a user library is cumbersome, because it requires non-trivial platform specific logic, which is already present and tested in os/exec package.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions