fix: add -WindowStyle Hidden to powershell command to prevent window flash on Windows (#285)

This commit is contained in:
paisley
2026-03-04 14:51:44 +08:00
committed by GitHub
Unverified
parent 30b03add1c
commit 9703f361f9
2 changed files with 74 additions and 3 deletions

View File

@@ -722,8 +722,10 @@ export class GatewayManager extends EventEmitter {
try {
// Platform-specific command to find processes listening on the gateway port.
// On Windows, lsof doesn't exist; use PowerShell's Get-NetTCPConnection instead.
// -WindowStyle Hidden is used to prevent PowerShell from popping up a brief console window
// even when windowsHide: true is passed to cp.exec.
const cmd = process.platform === 'win32'
? `powershell -NoProfile -Command "(Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue).OwningProcess"`
? `powershell -WindowStyle Hidden -NoProfile -Command "(Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue).OwningProcess"`
: `lsof -i :${port} -sTCP:LISTEN -t`;
const { stdout } = await new Promise<{ stdout: string }>((resolve, reject) => {
@@ -754,10 +756,12 @@ export class GatewayManager extends EventEmitter {
for (const pid of pids) {
try {
if (process.platform === 'win32') {
// On Windows, use taskkill for reliable process group termination
// Use PowerShell with -WindowStyle Hidden to kill the process without
// flashing a black console window. taskkill.exe is a console app and
// can flash a window even when windowsHide: true is set.
import('child_process').then(cp => {
cp.exec(
`taskkill /PID ${pid} /T /F`,
`powershell -WindowStyle Hidden -NoProfile -Command "Stop-Process -Id ${pid} -Force -ErrorAction SilentlyContinue"`,
{ timeout: 5000, windowsHide: true },
() => { }
);