-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
executable file
·47 lines (41 loc) · 894 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"syscall"
)
func isProcessExist(appName string) (bool, string, int) {
appary := make(map[string]int)
cmd := exec.Command("cmd", "/C", "tasklist")
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
output, _ := cmd.Output()
//fmt.Printf("fields: %v\n", output)
n := strings.Index(string(output), "System")
if n == -1 {
fmt.Println("no find")
os.Exit(1)
}
data := string(output)[n:]
fields := strings.Fields(data)
for k, v := range fields {
if v == appName {
appary[appName], _ = strconv.Atoi(fields[k+1])
return true, appName, appary[appName]
}
}
return false, appName, -1
}
//IsExists 检测文件是否存在
func IsExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}