os.Exec pitfalls

suggest change

exec.Cmd cannot be reused

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

main.go

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

	_, err = cmd.CombinedOutput()
	if err != nil {
		log.Fatalf("second cmd.CombintedOutput() failed with '%s'\n", err)
	}

Output:

2020/07/12 07:36:21 second cmd.CombintedOutput() 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