diff --git a/execute.go b/execute.go index f4d3876..95c560b 100644 --- a/execute.go +++ b/execute.go @@ -5,13 +5,22 @@ import ( "os/exec" ) -// Execute is used to run a command and print -// the value in stdout and stderr -func Execute(command []string) { +// Execute is used to run a command and print the value in stdout and stderr. +// +// The return value contains the command's exit code. +func Execute(command []string) int { cmd := exec.Command(command[0], command[1:]...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.Run() + if err := cmd.Run(); err != nil { + if exitError, ok := err.(*exec.ExitError); ok { + return exitError.ExitCode() + } + + return -1 + } + + return 0 } diff --git a/main.go b/main.go index 6dc8cab..309c7c2 100644 --- a/main.go +++ b/main.go @@ -62,5 +62,5 @@ func main() { return } - Execute(command) + os.Exit(Execute(command)) }