Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit acfda0e

Browse files
committed
Fix: kill process err after 6 second
1 parent 193d29e commit acfda0e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

FyneApp.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Website = "https://mcsmanager.com/"
55
Name = "MCSManager-Launcher"
66
ID = "mcsmanager.com"
77
Version = "1.2.0"
8-
Build = 3
8+
Build = 5

cmd/cmd.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import (
1414
)
1515

1616
type ProcessMgr struct {
17-
Path string
18-
Args []string
19-
Started bool
20-
stdin io.WriteCloser
21-
startErr chan error
22-
exited chan error
23-
cmder *exec.Cmd
24-
Cwd string
17+
Path string
18+
Args []string
19+
Started bool
20+
stdin io.WriteCloser
21+
startErr chan error
22+
exited chan error
23+
cmder *exec.Cmd
24+
Cwd string
25+
StartCount int
2526
}
2627

2728
func NewProcessMgr(workDir string, path string, args ...string) *ProcessMgr {
@@ -49,6 +50,7 @@ func (pm *ProcessMgr) Start() error {
4950
func (pm *ProcessMgr) run() {
5051
os.Chdir(pm.Cwd)
5152
fmt.Printf("Change CWD: %s\n", pm.Cwd)
53+
pm.StartCount += 1
5254
pm.cmder = exec.Command(pm.Path, pm.Args...)
5355
if runtime.GOOS == "windows" {
5456
pm.cmder.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
@@ -77,9 +79,10 @@ func (pm *ProcessMgr) End() error {
7779

7880
func (pm *ProcessMgr) ExitCheck() {
7981
go func() {
82+
tmpStartCount := pm.StartCount
8083
time.Sleep(6 * time.Second)
8184
fmt.Printf("Program kill, Status: %v", pm.Started)
82-
if pm.Started {
85+
if pm.Started && pm.StartCount == tmpStartCount {
8386
pid := pm.cmder.Process.Pid
8487
fmt.Printf("Kill Program: taskkill /PID %d /T /F\n", pid)
8588
cmder := exec.Command("taskkill", "/PID", strconv.Itoa(pid), "/T", "/F")

0 commit comments

Comments
 (0)