Skip to content

Instantly share code, notes, and snippets.

@ymgyt
Created March 8, 2018 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ymgyt/5163ea02128adb4c0331f0a81720b307 to your computer and use it in GitHub Desktop.
Save ymgyt/5163ea02128adb4c0331f0a81720b307 to your computer and use it in GitHub Desktop.
exec.Command example
func (b *builder) Build() error {
args := append([]string{"go", "build", "-o", filepath.Join(b.wd, b.binary)}, b.buildArgs...)
var command *exec.Cmd
if b.useGodep {
args = append([]string{"godep"}, args...)
}
command = exec.Command(args[0], args[1:]...)
command.Dir = b.dir
output, err := command.CombinedOutput()
if command.ProcessState.Success() {
b.errors = ""
} else {
b.errors = string(output)
}
if len(b.errors) > 0 {
return fmt.Errorf(b.errors)
}
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment