deputy icon indicating copy to clipboard operation
deputy copied to clipboard

Get the exit code

Open telemac opened this issue 8 years ago • 1 comments

Hi,

Is there a way to get the exit code of the called process ? Thank you

telemac avatar Oct 24 '17 08:10 telemac

I could add that code, definitely. Barring that, you can do it yourself:

type exitStatus interface {
	ExitStatus() int
}

// ExitStatus returns the exit status of the error if it is an exec.ExitError
// or if it implements ExitStatus() int.
// 0 if it is nil or 1 if it is a different error.
func ExitStatus(err error) int {
	if err == nil {
		return 0
	}
	if e, ok := err.(exitStatus); ok {
		return e.ExitStatus()
	}
	if e, ok := err.(*exec.ExitError); ok {
		if ex, ok := e.Sys().(exitStatus); ok {
			return ex.ExitStatus()
		}
	}
	return 1
}

natefinch avatar Oct 25 '17 01:10 natefinch