@@ -14,7 +14,8 @@ import { z } from "zod";
|
14 | 14 | import { resolveConfigPath, resolveGatewayLockDir, resolveStateDir } from "../config/paths.js"; |
15 | 15 | import { isPidAlive } from "../shared/pid-alive.js"; |
16 | 16 | import { safeParseJsonWithSchema } from "../utils/zod-parse.js"; |
17 | | -import { isGatewayArgv, parseProcCmdline, parseWindowsCmdline } from "./gateway-process-argv.js"; |
| 17 | +import { isGatewayArgv, parseProcCmdline } from "./gateway-process-argv.js"; |
| 18 | +import { readWindowsProcessArgsSync } from "./windows-port-pids.js"; |
18 | 19 | |
19 | 20 | const DEFAULT_TIMEOUT_MS = 5000; |
20 | 21 | const DEFAULT_POLL_INTERVAL_MS = 100; |
@@ -79,32 +80,8 @@ function readLinuxCmdline(pid: number): string[] | null {
|
79 | 80 | |
80 | 81 | const CMDLINE_EXEC_TIMEOUT_MS = 1000; |
81 | 82 | |
82 | | -/** |
83 | | - * Read the command line of a Windows process via `wmic`. |
84 | | - * Returns an argv-style array, or null when the lookup fails (process gone, |
85 | | - * `wmic` missing/deprecated, timeout, etc.). |
86 | | - */ |
87 | 83 | function readWindowsCmdline(pid: number): string[] | null { |
88 | | -try { |
89 | | -// Omit `encoding` so execFileSync returns a Buffer — wmic emits UTF-16LE |
90 | | -// (with BOM) on most Windows 10/11 builds, which would be garbled as UTF-8. |
91 | | -const buf = execFileSync( |
92 | | -"wmic", |
93 | | -["process", "where", `processid=${pid}`, "get", "CommandLine", "/value"], |
94 | | -{ timeout: CMDLINE_EXEC_TIMEOUT_MS, windowsHide: true, stdio: ["ignore", "pipe", "ignore"] }, |
95 | | -) as Buffer; |
96 | | -const raw = |
97 | | -buf.length >= 2 && buf[0] === 0xff && buf[1] === 0xfe |
98 | | - ? buf.toString("utf16le") |
99 | | - : buf.toString("utf8"); |
100 | | -const match = raw.match(/CommandLine=(.+)/); |
101 | | -if (!match) { |
102 | | -return null; |
103 | | -} |
104 | | -return parseWindowsCmdline(match[1].trim()); |
105 | | -} catch { |
106 | | -return null; |
107 | | -} |
| 84 | +return readWindowsProcessArgsSync(pid, CMDLINE_EXEC_TIMEOUT_MS); |
108 | 85 | } |
109 | 86 | |
110 | 87 | /** |
|