Skip to content

Commit

Permalink
add .LastExitCode
Browse files Browse the repository at this point in the history
  • Loading branch information
kokizzu committed May 13, 2024
1 parent 2fe9a5d commit 208d1ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require github.com/kokizzu/gotro v1.4105.455

require (
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/jxskiss/base62 v1.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/jxskiss/base62 v1.1.0 h1:A5zbF8v8WXx2xixnAKD2w+abC+sIzYJX+nxmhA6HWFw=
Expand Down
6 changes: 6 additions & 0 deletions goproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package goproc

import (
"bufio"
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -60,6 +61,7 @@ type Cmd struct {

MaxRestart int // -1 = always restart, 0 = only run once, >0 run N times
LastExecutionError error // last execution error, useful for OnProcessCompleted or ProcessCompletedChannel
LastExitCode int // last exit code, will be set before OnProcessCompleted
RestartCount int // can be overwritten for early exit or restart from 0

OnStdout StringCallback // one line fetched from stdout
Expand Down Expand Up @@ -344,6 +346,10 @@ func (g *Goproc) Start(cmdId CommandId) error {
}
}
cmd.LastExecutionError = err
var ee *exec.ExitError
if errors.As(err, &ee) {
cmd.LastExitCode = ee.ExitCode()
}

if cmd.OnProcessCompleted != nil {
durationMs := time.Since(start).Milliseconds()
Expand Down

0 comments on commit 208d1ac

Please sign in to comment.