Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed May 30, 2024
1 parent f63f54c commit c49c389
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@ func TestCommandCancel(t *testing.T) {
if err != nil {
t.Fatalf("%v: %v", tt.cmd, err)
}
go func() {
cmd.Wait()
}()
if !checkprocess() && !tt.processFinished {
t.Errorf("%v: %s", tt.cmd, "the process has been exited")
}
_ = cmd.Cancel()

if checkprocess() {
t.Errorf("%v: %s", tt.cmd, "the process has not exited")
}
Expand All @@ -246,6 +250,7 @@ func checkprocess() bool {
} else {
out, err = exec.Command("bash", "-c", "ps aux | grep stubcmd | grep -v grep").Output()
}

return (err == nil || strings.TrimRight(string(out), "\n\r") != "")
}

Expand All @@ -257,8 +262,11 @@ func killprocess() error {
if runtime.GOOS == "windows" {
out, err = exec.Command("taskkill", "/im", "stubcmd.exe").Output()
} else {
out, err = exec.Command("bash", "-c", "ps aux | grep stubcmd | grep -v grep | xargs kill").Output()
out, err = exec.Command("bash", "-c", "ps aux | grep stubcmd | grep -v grep | xargs kill -9").Output()
}

fmt.Println("checkprocess", string(out))

if err != nil {
if strings.TrimRight(string(out), "\n\r") != "" {
_, _ = fmt.Fprintf(os.Stderr, "%s", string(out))
Expand Down

0 comments on commit c49c389

Please sign in to comment.