兼容传入的工作目录为空的场景

This commit is contained in:
白茶清欢 2022-05-21 19:40:33 +08:00
parent eff08782cf
commit 2f8be1dea3

View File

@ -44,7 +44,7 @@ func Execute(workDir string, command string, param []string) define.Result {
var ( var (
fileInfo os.FileInfo fileInfo os.FileInfo
) )
if fileInfo, result.Error = os.Stat(workDir); nil != result.Error { if fileInfo, result.Error = os.Stat(result.WorkDir); nil != result.Error {
if !os.IsExist(result.Error) { if !os.IsExist(result.Error) {
return result return result
} }
@ -53,14 +53,14 @@ func Execute(workDir string, command string, param []string) define.Result {
} }
if !fileInfo.IsDir() { if !fileInfo.IsDir() {
result.Error = errors.New(workDir + " 工作目录不存在") result.Error = errors.New(result.WorkDir + " 工作目录不存在")
} }
if result.CmdPath, result.Error = Check(command); nil != result.Error { if result.CmdPath, result.Error = Check(command); nil != result.Error {
return result return result
} }
cmdInstance := exec.Command(command, param...) cmdInstance := exec.Command(command, param...)
cmdInstance.Dir = workDir cmdInstance.Dir = result.WorkDir
result.Output, result.Error = cmdInstance.CombinedOutput() result.Output, result.Error = cmdInstance.CombinedOutput()
return result return result
} }