diff --git a/execute.go b/execute.go index 7c5b1e6..8c334d3 100644 --- a/execute.go +++ b/execute.go @@ -9,6 +9,7 @@ package command import ( "errors" + "os" "os/exec" "time" @@ -32,6 +33,21 @@ func Execute(workDir string, command string, param []string) define.Result { defer func() { result.FinishTime = time.Now().UnixNano() }() + var ( + fileInfo os.FileInfo + ) + if fileInfo, result.Error = os.Stat(workDir); nil != result.Error { + if !os.IsExist(result.Error) { + return result + } + // 目录已存在 + result.Error = nil + } + + if !fileInfo.IsDir() { + result.Error = errors.New(workDir + " 工作目录不存在") + } + if result.CmdPath, result.Error = Check(command); nil != result.Error { return result }