Skip to content

proposal: os/exec: new function LookPaths #54688

@nnzv

Description

@nnzv

The name of an executable could be found in different paths (e.g, different versions of the same executable). LookPath is internally used to find what and retrieves something to run. Thus, I don't feel strong to modify what it retrieves to accomplish this purpose.

Instead, I've thought about a new function called LookPaths to give all possible matches of the wanted executable's name rather than the first matched occurrence.

For example, in case want all possible paths of bash:

package main

import (
    "fmt"
    "log"
    "os/exec"
)

func main() {
    path, err := exec.LookPaths("bash")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(path)
    // Sample Output: [/bin/bash /usr/bin/bash /usr/local/bin/bash]
}

In regards to an archaic design of LookPaths:

func LookPaths(file string) ([]string, error) { 
    // ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions