Created
March 8, 2018 11:36
-
-
Save ymgyt/5163ea02128adb4c0331f0a81720b307 to your computer and use it in GitHub Desktop.
exec.Command example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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