Skip to content

๐Ÿ” find app path and print it.

License

Notifications You must be signed in to change notification settings

abdfnx/looker

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Looker

๐Ÿ” find app path and print it.

A alternative package to exec.LookPath().

The problem

The following code, relatively common approach to running external commands has a vulnerability on Windows:

import "os/exec"

func gitAdd() error {
    cmd := exec.Command("git", "add", "Formula")
    return cmd.Run()
}

Searching the current directory (surprising behavior) before searching folders listed in the PATH environment variable (expected behavior) seems to be intended in Go and unlikely to be changed go#38736

Install

go get -v github.com/abdfnx/looker@v0.1.0

Example:

import (
    "os/exec"

    "github.com/abdfnx/looker"
)

func gitAdd() error {
    gitPath, err := looker.LookPath("git")

    if err != nil {
        return err
    }

    cmd := exec.Command(gitPath, "add", "Formula")
    return cmd.Run()
}