Skip to content

Commit

Permalink
exit status N というエラー表示を抑制するようにした。
Browse files Browse the repository at this point in the history
  • Loading branch information
hymkor committed Sep 27, 2014
1 parent fbbf081 commit 24247ed
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package interpreter
import "io"
import "os"
import "os/exec"
import "regexp"
import "strconv"

type NextT int

Expand Down Expand Up @@ -40,6 +42,9 @@ func SetHook(hook_ HookT) (rv HookT) {
return
}

var errorStatusPattern = regexp.MustCompile("^exit status\\s*(\\d+)")
var ErrorLevel int

func Interpret(text string, stdio *Stdio) (NextT, error) {
statements := Parse(text)
for _, pipeline := range statements {
Expand Down Expand Up @@ -144,6 +149,14 @@ func Interpret(text string, stdio *Stdio) (NextT, error) {
if pipeOut != nil {
pipeOut.Close()
}
if err != nil {
m := errorStatusPattern.FindStringSubmatch(err.Error())
if m != nil {
ErrorLevel, err = strconv.Atoi(m[1])
} else {
ErrorLevel = 0
}
}
if whatToDo == SHUTDOWN {
return SHUTDOWN, err
}
Expand Down

0 comments on commit 24247ed

Please sign in to comment.