os.Exec pitfalls

suggest change

exec.Cmd cannot be reused

An exec.Cmd cannot be reused after calling its Run, Output or CombinedOutput methods.

	cmd := exec.Command("go", "version")
	_, err := cmd.CombinedOutput()
	if err != nil {
		log.Fatalf("first cmd.CombinedOutput() failed with '%s'\n", err)
	}

	_, err = cmd.CombinedOutput()
	if err != nil {
		log.Fatalf("second cmd.CombinedOutput() failed with '%s'\n", err)
	}
2020/07/12 07:36:21 second cmd.CombinedOutput() failed with 'exec: Stdout already set'
exit status 1

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents