mercredi 26 août 2020

How to run a go command from inside go code itself?

First of all, note that I'm far from a go expert, and I'm trying to create a simple go package to be able to run go tests passing a blacklist as a parameter, which means it would test all the packages except for those in the list.

My current approach involves running commands like go list ./... (to get a list os packages) and go test from inside my code itself.

I've trying to do so like this:

func main() {
    out, err := exec.Command("go list", "./...").Output()

    if err != nil {
        fmt.Printf("%s", err)
    }

    output := string(out[:])
    fmt.Println

Which results on the following error:

exec: "go list": executable file not found in %PATH%

What would be the correct (or better) approach for achieving my goal?

Aucun commentaire:

Enregistrer un commentaire