On Sun, Apr 5, 2020 at 3:36 PM R Srinivasan <s...@srin.me> wrote: > > I cannot figure the error in the following. > package main > > import ( > "io" > "os" > "os/exec" > "strings" > ) > > func Run(args []string) { > lf, _ := os.Create("lf.log") > defer lf.Close() > cmd := exec.Command(args[0], strings.Join(args[1:], " ")) > stderr, _ := cmd.StderrPipe() > cmd.Start() > io.Copy(lf, stderr) > cmd.Wait() > } > > func main() { > args := []string{"go", "build", "./"} > Run(args) > } > > I can execute go build ./ and get an executable. However when I run it I get > the following in the logfile: > > cat lf.log go build ./: unknown command Run 'go help build' for usage. > > I exected that the "exec" will just execute go build ./ > > I did rename the exe to something else before running it. > > Anyone can spot the error?
Besides other comments, always check your error returns. Do that before you ask for help on any program. Thanks. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUH%2BZKwvLJuUCB9FZNHopz_cAuAXR0%3DnbWz1reYMM0%3DUg%40mail.gmail.com.