I made a little hack in Go for my needs to run 3rd party executable with dynamic flags (which depend on server settings and some hardware specs, so different on each machine and each time).
I'm using some neat library to help me out find which path is Go executable located in. The 3rd party binary is in same folder as Go one.
path, err := osext.ExecutableFolder()
if err != nil {
log.Fatal(err)
}
path += "3rdparty.exe"
I than run the fmt's Sprintf
method, to put path and flags into single string called Command.
I try to invoke it like so:
out, err := exec.Command(Command).Output()
if err != nil {
fmt.Println("Command execution failed:", err)
}
However err isn't nil. I can't copy error out of vmware (setup windows there just to compile and test), but it goes like: Command execution failed: "C:\\PATH\\TO\\3rdparty.exe --flags-omitted" file does not exist
However when I copy C:\\PATH\\TO\\3rdparty.exe --flags-omitted
into cmd it runs perfectly.
Any ideas?
The command and its parametets must be separate strings, do not join them into a single string.
At a closer look, the error message actually is clear about it (note where the quotes are):
Command execution failed: "C:\\PATH\\TO\\3rdparty.exe --flags-omitted" file does not exist