Skip to content

Commit 19544cf

Browse files
committed
update
1 parent 05b7896 commit 19544cf

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

cmd.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"bytes"
2424
"context"
2525
"errors"
26-
"fmt"
2726
"io"
2827
"log"
2928
"os"
@@ -60,7 +59,7 @@ func ExecCmdDirBytesWithContext(ctx context.Context, dir, cmdName string, args .
6059
err := cmd.Run()
6160
if err != nil {
6261
if e, y := err.(*exec.ExitError); y {
63-
OnCmdExitError(append([]string{cmdName}, args...), e)
62+
OnCmdExitError(cmd, e)
6463
} else {
6564
cmd.Stderr.Write([]byte(err.Error() + "\n"))
6665
}
@@ -515,8 +514,8 @@ func RunCmdStrWriterWithContext(ctx context.Context, command string, writer ...i
515514
return RunCmdWriterWithContext(ctx, params, writer...)
516515
}
517516

518-
var OnCmdExitError = func(params []string, err *exec.ExitError) {
519-
fmt.Printf("[%v]The process exited abnormally: PID(%d) PARAMS(%v) ERR(%v)\n", time.Now().Format(`2006-01-02 15:04:05`), err.Pid(), params, err)
517+
var OnCmdExitError = func(cmd *exec.Cmd, err *exec.ExitError) {
518+
log.Printf("[%v]The process exited abnormally: PID(%d) CMD(%v) ERR(%v)\n", time.Now().Format(`2006-01-02 15:04:05`), err.Pid(), cmd.String(), err)
520519
}
521520

522521
func RunCmdReaderWriterWithContext(ctx context.Context, params []string, reader io.Reader, writer ...io.Writer) *exec.Cmd {
@@ -527,7 +526,7 @@ func RunCmdReaderWriterWithContext(ctx context.Context, params []string, reader
527526
err := cmd.Run()
528527
if err != nil {
529528
if e, y := err.(*exec.ExitError); y {
530-
OnCmdExitError(params, e)
529+
OnCmdExitError(cmd, e)
531530
} else {
532531
cmd.Stderr.Write([]byte(err.Error() + "\n"))
533532
}
@@ -552,7 +551,7 @@ func RunCmdWriterWithContext(ctx context.Context, params []string, writer ...io.
552551
err := cmd.Run()
553552
if err != nil {
554553
if e, y := err.(*exec.ExitError); y {
555-
OnCmdExitError(params, e)
554+
OnCmdExitError(cmd, e)
556555
} else {
557556
cmd.Stderr.Write([]byte(err.Error() + "\n"))
558557
}
@@ -587,7 +586,7 @@ func RunCmdWriterxWithContext(ctx context.Context, params []string, wait time.Du
587586
err = cmd.Run()
588587
if err != nil {
589588
if e, y := err.(*exec.ExitError); y {
590-
OnCmdExitError(params, e)
589+
OnCmdExitError(cmd, e)
591590
} else {
592591
cmd.Stderr.Write([]byte(err.Error() + "\n"))
593592
}

0 commit comments

Comments
 (0)