执行命令时,增加判断工作目录是否存在
This commit is contained in:
parent
b675aceb33
commit
6e8f81cee0
16
execute.go
16
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user