Skip to content

Commit cc29beb

Browse files
author
woytu
committed
判断执行脚本是否存在
1 parent 4ce05a3 commit cc29beb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

utils/exec.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package utils
22

33
import (
4+
"errors"
5+
"fmt"
46
"os/exec"
57
"runtime"
68
)
@@ -12,6 +14,10 @@ import (
1214
* @date 2019/6/28 14:19
1315
*/
1416
func ExecutePython(script string, args ...string) (result string, err error) {
17+
if !IsFile(script) {
18+
err = errors.New(fmt.Sprintf(script, "error:%s", "文件不存在"))
19+
return "", err
20+
}
1521
name := "python"
1622
if runtime.GOOS == "linux" {
1723
name = "python3"
@@ -25,8 +31,6 @@ func ExecutePython(script string, args ...string) (result string, err error) {
2531
return string(out), err
2632
}
2733
result = string(out)
28-
//if strings.Index(result, "success") != 0 {
29-
// err = errors.New(fmt.Sprintf(script, "error:%s", result))
30-
//}
34+
3135
return result, nil
3236
}

0 commit comments

Comments
 (0)