Created
March 30, 2020 09:13
-
-
Save makotom/7192a6741598af3eb3207f2affebf169 to your computer and use it in GitHub Desktop.
"Go" this time: https://gist.github.com/makotom/e5828ec36f277b81a0eceaf70d0c5921
This file contains 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 ( | |
"fmt" | |
"bytes" | |
"os/exec" | |
"syscall" | |
) | |
func main() { | |
var out bytes.Buffer | |
userCmd := `dir "C:\Program Files"` | |
sysProcAttr := syscall.SysProcAttr{ | |
CmdLine: fmt.Sprintf(`/C "%s"`, userCmd), | |
} | |
cmd := exec.Command("cmd.exe") | |
cmd.SysProcAttr = &sysProcAttr | |
cmd.Stdout = &out | |
cmd.Stderr = &out | |
err := cmd.Run() | |
fmt.Printf("%s\n", out.String()) | |
fmt.Printf("%v\n", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment