V
V
Vladimir Grabko2016-04-24 16:38:04
go
Vladimir Grabko, 2016-04-24 16:38:04

Why is it looking for a file instead of running a command?

Good afternoon. I needed to launch files from under golang. Googled, I realized that there is no way out except for exec. So quickly I googled the start command. Opened cmd.exe launched the software. I also wrote it myself in golang

//windows
    log.Print(c[1])
    cmd := exec.Command("start", strings.TrimSpace(c[1]))
    err := cmd.Start()
    if err != nil {
      log.Print(err)
    }
    log.Printf("Waiting for command to finish...")
    err = cmd.Wait()
    log.Printf("Command finished with error: %v", err)

when starting from under go, it writes to the log
2016/04/24 16:30:24 commands.go:23: exec: "start": executable file not found in %PATH%
2016/04/24 16:30:24 commands.go:25: Waiting for command to finish...
2016/04/24 16:30:24 commands.go:27: Command finished with error: exec: not started

judging from the log, exec is looking for the start .COM; .EXE; .BAT; .CMD file, but since it does not exist, it says an error. How to force golang not to search for a file, but to execute a system command?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uvelichitel, 2016-04-24
@lucifer-m

Try

cmd  := exec.Command("cmd", "/C", "start", "", strings.TrimSpace(c[1]))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question