From d4e7b563bc0689efa6952487c3d944673487438c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 20 May 2022 22:31:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E=E7=BB=93?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- define/result.go | 2 ++ execute.go | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) 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()