Trying to execute the command to compile the Golang program, code:
var buildCommand = fmt.Sprintf("go build %s %s main.go", `-v -a -x`, `-ldflags="-w -s"`); var cmd = exec.Command(buildCommand) var err = cmd.Run() If I buildCommand variable buildCommand I will get:
go build -v -a -x -ldflags="-w -s" main.go
but when you run the program itself, the builder will issue: exec: "go build -v -a -x -ldflags=\"-w -s\" main.go , that is, add such signs "\ \" , and exec.Command itself exec.Command it adds, how can this be fixed?
exec.Command()incorrectly. The first argument should be the name of the command i.goand you givego build -v -a -x -ldflags="-w -s" main.goAnd further `` is the result of building a string for the error. View examples golang.org/pkg/os/exec/#Command - biosckon