Essential Go Executing commands  Edit on GitHub      File Issue

os.Exec gotchas

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.CombintedOutput() failed with '%s'\n", err)
}

_, err = cmd.CombinedOutput()
if err != nil {
	log.Fatalf("second cmd.CombintedOutput() failed with '%s'\n", err)
}
2018/03/09 00:42:38 second cmd.CombintedOutput() failed with 'exec: Stdout already set'
exit status 1
  ↑ ↓ to navigate     ↵ to select     Esc to close