Last active
March 22, 2017 19:23
-
-
Save mohae/16862996c67baba1fdac20160df37fdf to your computer and use it in GitHub Desktop.
exec.Command on windows with spaces in the path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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