执行命令时,增加判断工作目录是否存在

This commit is contained in:
白茶清欢 2022-05-21 17:54:53 +08:00
parent b675aceb33
commit 6e8f81cee0

View File

@ -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
}