Skip to content

Commit

Permalink
fix: use cmd.Wait ExitCode
Browse files Browse the repository at this point in the history
  • Loading branch information
fcying committed Sep 23, 2024
1 parent f972d38 commit 0422be8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
19 changes: 10 additions & 9 deletions internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -96,30 +97,30 @@ func MakeWrap(args []string) {
// cmd.Stderr = os.Stderr
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Error("Error:", err)
return
fmt.Println("stdout Error:", err)
goto out
}
stderr, err := cmd.StderrPipe()
if err != nil {
log.Error("Error:", err)
return
fmt.Println("stderr Error:", err)
goto out
}

if err := cmd.Start(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
StatusCode = exitError.ExitCode()
log.Errorf("make failed! errorCode: %d", StatusCode)
}
fmt.Println("start Error:", err)
goto out
}

go TransferPrintScanner(stdout)
go TransferPrintScanner(stderr)

if err := cmd.Wait(); err != nil {
log.Error("Error:", err)
StatusCode = cmd.ProcessState.ExitCode()
fmt.Printf("make failed! errorCode: %d\n", StatusCode)
}
}

out:
wg.Wait()
}

Expand Down
5 changes: 2 additions & 3 deletions internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os/exec"
"strings"

log "github.com/sirupsen/logrus"
"golang.org/x/text/encoding/simplifiedchinese"
)

Expand Down Expand Up @@ -56,13 +55,13 @@ func TransferPrintScanner(in io.ReadCloser) {
for scanner.Scan() {
result, err := decoder.String(scanner.Text())
if err != nil {
log.Error("decode failed!", scanner.Text())
fmt.Println("decode failed!", scanner.Text())
result = ""
}
fmt.Println(result)
}

if err := scanner.Err(); err != nil {
log.Error("Error reading scanner:", err)
fmt.Println("Error reading scanner:", err)
}
}

0 comments on commit 0422be8

Please sign in to comment.