Skip to content

Windows: stop/status/restart commands broken due to Unix-only process management #74

@Alexander-He

Description

@Alexander-He

Description

On Windows, the weclaw stop, weclaw status, and weclaw restart commands do not work correctly. The process management code in cmd/start.go uses Unix-only APIs (syscall.SIGTERM, p.Signal(0), pkill) that are either unavailable or behave differently on Windows.

Affected Commands

1. weclaw stop

  • Prints "weclaw stopped" but does not actually kill the process
  • stopAllWeclaw() uses p.Signal(syscall.SIGTERM) which does not terminate processes on Windows
  • Falls back to exec.Command("pkill", ...) which is a Unix-only command — will fail silently on Windows
  • Verified: after running weclaw stop, Get-Process -Name weclaw still shows the process running

2. weclaw status

  • Prints "weclaw is not running" even when the process is actively running
  • processExists() uses os.FindProcess(pid) + p.Signal(syscall.Signal(0))
  • On Windows, os.FindProcess always succeeds regardless of whether the process exists, and Signal(0) is not a valid operation
  • Verified: weclaw status reports "not running" while the process is actually processing WeChat messages

3. weclaw restart

  • Inherits both broken behaviors from stopAllWeclaw() and processExists()
  • The 10-second wait loop (20 x 500ms) will always time out because processExists() never returns false

Root Cause

All affected functions are in cmd/start.go:

  • processExists(pid int) bool (line 426-433) — uses Unix signal 0 probe
  • stopAllWeclaw() (line 436-452) — uses SIGTERM + pkill

Suggested Fix

  1. processExists() on Windows: Use OpenProcess API via syscall, or fall back to tasklist /FI "PID eq %d"
  2. stopAllWeclaw() on Windows: Use taskkill /F /PID %d or TerminateProcess instead of SIGTERM + pkill
  3. Use build tags (//go:build windows) for platform-specific implementations, similar to the existing proc_windows.go

Environment

  • OS: Windows 11 (amd64)
  • WeClaw version: v0.7.1 (pre-built Windows binary)
  • Reproduce: run weclaw start, then weclaw status or weclaw stop

Workaround

Stop-Process -Name weclaw   # instead of weclaw stop
Get-Process -Name weclaw     # instead of weclaw status

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions