Skip to content

Instantly share code, notes, and snippets.

@mohae
Last active March 22, 2017 19:23
Show Gist options
  • Select an option

  • Save mohae/16862996c67baba1fdac20160df37fdf to your computer and use it in GitHub Desktop.

Select an option

Save mohae/16862996c67baba1fdac20160df37fdf to your computer and use it in GitHub Desktop.
exec.Command on windows with spaces in the path
package main
import (
"bytes"
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("C:\\Program Files (x86)\\Notepad++\\notepad++.exe", "C:\\Program Files (x86)\\Notepad++\\LICENSE")
var b bytes.Buffer
cmd.Stdout = &b
err := cmd.Start()
if err != nil {
fmt.Println(err)
return
}
err = cmd.Wait()
if err != nil {
fmt.Println(err)
}
fmt.Println(b.Bytes())
fmt.Println("done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment