// Wait calls Wait on the underlying exec.Cmd's Process and, if the // operating system supports it, returns the exit status. // // If an error occurs when waiting for the underlying process, the exit // status will be -2, and the error will be returned. If the operating // system does not support determining the exit status, but the program // exited successfully, the exit status will be 0. If the operating // system does not support determining the exit status and the program // exited unsuccessfully, the exit status will be -1. func (p *Proc) Wait() (exitStatus int, err error) { var ps *os.ProcessState ps, err = p.Cmd.Process.Wait() if err != nil { return -2, err } ws, ok := ps.Sys().(syscall.WaitStatus) if ok { return ws.ExitStatus(), nil } if ps.Success() { return 0, nil } return -1, nil }
func getExitCode(state *os.ProcessState) int { return state.Sys().(syscall.WaitStatus).ExitStatus() }
func exitStatus(p *os.ProcessState) int { ws := p.Sys().(syscall.WaitStatus) return ws.ExitStatus() }
func GetErrorLevel(processState *os.ProcessState) (int, bool) { if processState.Success() { return 0, true } else if t, ok := processState.Sys().(syscall.WaitStatus); ok { return t.ExitStatus(), true } else { return 255, false } }