mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
fix(cli): resolve daemon executable path without wmic
This commit is contained in:
@@ -35,29 +35,75 @@ function resolveNodePathFromPidUnix(pid: number): NodePathFromPidResult {
|
|||||||
return resolved ? { nodePath: resolved } : { nodePath: null, error: "ps returned an empty command path" };
|
return resolved ? { nodePath: resolved } : { nodePath: null, error: "ps returned an empty command path" };
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveNodePathFromPidWindows(pid: number): NodePathFromPidResult {
|
function runProcessProbe(command: string, args: string[]): {
|
||||||
const result = spawnSync(
|
resolved: string | null;
|
||||||
"wmic",
|
error?: string;
|
||||||
["process", "where", `ProcessId=${pid}`, "get", "ExecutablePath", "/VALUE"],
|
} {
|
||||||
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] },
|
const result = spawnSync(command, args, {
|
||||||
);
|
encoding: "utf8",
|
||||||
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
|
});
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
return { nodePath: null, error: `wmic failed: ${normalizeError(result.error)}` };
|
return { resolved: null, error: `${command} failed: ${normalizeError(result.error)}` };
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result.status ?? 1) !== 0) {
|
if ((result.status ?? 1) !== 0) {
|
||||||
const details = result.stderr?.trim();
|
const details = result.stderr?.trim();
|
||||||
return {
|
return {
|
||||||
nodePath: null,
|
resolved: null,
|
||||||
error: details ? `wmic failed: ${details}` : `wmic exited with code ${result.status ?? 1}`,
|
error: details ? `${command} failed: ${details}` : `${command} exited with code ${result.status ?? 1}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// wmic output format: "ExecutablePath=C:\path\to\node.exe\r\n"
|
const resolved = result.stdout.trim();
|
||||||
const match = result.stdout.match(/ExecutablePath=(.+)/);
|
return resolved ? { resolved } : { resolved: null, error: `${command} returned no executable path` };
|
||||||
const resolved = match?.[1]?.trim();
|
}
|
||||||
return resolved ? { nodePath: resolved } : { nodePath: null, error: "wmic returned no executable path" };
|
|
||||||
|
function resolveNodePathFromPidWindows(pid: number): NodePathFromPidResult {
|
||||||
|
const probes: Array<{ label: string; command: string; args: string[]; parseValue?: (stdout: string) => string | null }> = [
|
||||||
|
{
|
||||||
|
label: "powershell-cim",
|
||||||
|
command: "powershell",
|
||||||
|
args: [
|
||||||
|
"-NoProfile",
|
||||||
|
"-Command",
|
||||||
|
`(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").ExecutablePath`,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "powershell-process",
|
||||||
|
command: "powershell",
|
||||||
|
args: ["-NoProfile", "-Command", `(Get-Process -Id ${pid}).Path`],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "wmic",
|
||||||
|
command: "wmic",
|
||||||
|
args: ["process", "where", `ProcessId=${pid}`, "get", "ExecutablePath", "/VALUE"],
|
||||||
|
parseValue: (stdout) => {
|
||||||
|
const match = stdout.match(/ExecutablePath=(.+)/);
|
||||||
|
return match?.[1]?.trim() ?? null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const errors: string[] = [];
|
||||||
|
for (const probe of probes) {
|
||||||
|
const result = runProcessProbe(probe.command, probe.args);
|
||||||
|
if (result.resolved) {
|
||||||
|
const resolved = probe.parseValue ? probe.parseValue(result.resolved) : result.resolved;
|
||||||
|
if (resolved) {
|
||||||
|
return { nodePath: resolved };
|
||||||
|
}
|
||||||
|
errors.push(`${probe.label} returned no executable path`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (result.error) {
|
||||||
|
errors.push(`${probe.label}: ${result.error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { nodePath: null, error: errors.join("; ") || "could not resolve executable path from PID" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveNodePathFromPid(pid: number): NodePathFromPidResult {
|
export function resolveNodePathFromPid(pid: number): NodePathFromPidResult {
|
||||||
|
|||||||
Reference in New Issue
Block a user