Skip to content
This repository has been archived by the owner on Nov 14, 2021. It is now read-only.

Timothee-Cardoso/tc-exe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TC-EXE

exe runner for windows.

A Go module that provides a alternative to exec.LookPath() on Windows.

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

import "os/exec"

func goMod() error {
    cmd := exec.Command("go", "mod", "download)
    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: golang/go#38736

Example use:

import (
    "os/exec"
    tcexe "github.com/Timothee-Cardoso/tc-exe"
)

func goMod() error {
    goPath, err := tcexe.LookPath("git")

    if err != nil {
        return err
    }

    cmd := exec.Command(goPath, "mod", "download")
    return cmd.Run()
}