Go Execute Command

[Solved] Go Execute Command | Go - Code Explorer | yomemimo.com
Question : go execute command

Answered by : jealous-jellyfish-q092c51j8cdp

// 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
}

Source : | Last Update : Wed, 23 Feb 22

Question : how to execute a command in golang

Answered by : skillz

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()
}

Source : | Last Update : Sat, 01 Oct 22

Answers related to go execute command

Code Explorer Popular Question For Go