|
|
@@ -21,7 +21,7 @@ func findByPID() []int {
|
|
|
|
|
|
var pids []int
|
|
|
for _, line := range strings.Split(string(tasklistOut), "\n") {
|
|
|
- if pidRegex.MatchString(line) {
|
|
|
+ if pidRegex.MatchString(line) && !strings.Contains(line, "opencode-monitor") {
|
|
|
fields := strings.Split(line, ",")
|
|
|
if len(fields) >= 2 {
|
|
|
pidStr := strings.Trim(fields[1], "\"")
|
|
|
@@ -69,7 +69,7 @@ func findByCmdline() []int {
|
|
|
var ports []int
|
|
|
|
|
|
// 查找 opencode 进程
|
|
|
- wmicOut, err := exec.Command("wmic", "process", "where", "name like '%opencode%'", "get", "commandline", "/FORMAT:LIST").Output()
|
|
|
+ wmicOut, err := exec.Command("wmic", "process", "where", "name like '%opencode%' and name not like '%opencode-monitor%'", "get", "commandline", "/FORMAT:LIST").Output()
|
|
|
if err == nil {
|
|
|
for _, line := range strings.Split(string(wmicOut), "\n") {
|
|
|
if strings.Contains(line, "--port") {
|
|
|
@@ -110,7 +110,7 @@ func findByCmdline() []int {
|
|
|
|
|
|
// 使用 PowerShell 作为后备方案
|
|
|
if len(ports) == 0 {
|
|
|
- powershellOut, err := exec.Command("powershell", "-Command", "Get-CimInstance Win32_Process | Where-Object {$_.Name -like '*opencode*' -or ($_.Name -like '*bun*' -and $_.CommandLine -like '*opencode*')} | Select-Object CommandLine").Output()
|
|
|
+ powershellOut, err := exec.Command("powershell", "-Command", "Get-CimInstance Win32_Process | Where-Object {($_.Name -like '*opencode*' -and $_.Name -notlike '*opencode-monitor*') -or ($_.Name -like '*bun*' -and $_.CommandLine -like '*opencode*')} | Select-Object CommandLine").Output()
|
|
|
if err == nil {
|
|
|
for _, line := range strings.Split(string(powershellOut), "\n") {
|
|
|
if strings.Contains(line, "--port") {
|