xxxxxxxxxx
// ExecuteCommand execute cmd and returns the output
func ExecuteCommand(cmd string, args []string) ([]byte, error) {
cmd := exec.Command(cmd, args)
buf, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("cmd run failed: %v, msg: %s", err, string(buf))
}
return string(buf), nil
}
xxxxxxxxxx
func ExecuteCommand(command string) (error, string, string) {
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd := exec.Command("powershell", "-c", command)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
return err, stdout.String(), stderr.String()
}