diff --git a/.gitignore b/.gitignore index df8e306..b941df8 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,5 @@ # vendor/ .idea .vscode -mail_test.go +*_test.go diff --git a/define/result.go b/define/result.go index c2789ee..bc15520 100644 --- a/define/result.go +++ b/define/result.go @@ -13,6 +13,8 @@ package define // // Date : 22:00 2022/5/20 type Result struct { + WorkDir string // 执行的目录 + CmdPath string // 命令的路径 Err error // 异常信息 Output []byte // 输出的内容 StartTime int64 // 开始时间 diff --git a/execute.go b/execute.go index 57fdfe9..311f7f1 100644 --- a/execute.go +++ b/execute.go @@ -22,6 +22,7 @@ import ( func Execute(workDir string, command string, param []string) define.Result { //执行命令 result := define.Result{ + WorkDir: workDir, Err: nil, Output: nil, StartTime: time.Now().UnixNano(), @@ -30,6 +31,9 @@ func Execute(workDir string, command string, param []string) define.Result { defer func() { result.FinishTime = time.Now().UnixNano() }() + if result.CmdPath, result.Err = Check(command); nil != result.Err { + return result + } cmdInstance := exec.Command(command, param...) cmdInstance.Dir = workDir result.Output, result.Err = cmdInstance.CombinedOutput()