ExitStatus returns the integer exit status of a previous command (for example run by [Pipe.Exec]). This will be zero unless the pipe's error status is set and the error matches the pattern “exit status %d”.
()
| 510 | // example run by [Pipe.Exec]). This will be zero unless the pipe's error |
| 511 | // status is set and the error matches the pattern “exit status %d”. |
| 512 | func (p *Pipe) ExitStatus() int { |
| 513 | if p.Error() == nil { |
| 514 | return 0 |
| 515 | } |
| 516 | match := exitStatusPattern.FindStringSubmatch(p.Error().Error()) |
| 517 | if len(match) < 2 { |
| 518 | return 0 |
| 519 | } |
| 520 | status, err := strconv.Atoi(match[1]) |
| 521 | if err != nil { |
| 522 | // This seems unlikely, but... |
| 523 | return 0 |
| 524 | } |
| 525 | return status |
| 526 | } |
| 527 | |
| 528 | // Filter sends the contents of the pipe to the function filter and produces |
| 529 | // the result. filter takes an [io.Reader] to read its input from and an |