fix: harden windows cli launch
This commit is contained in:
@@ -1,5 +1,22 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
function resolvePowerShellPath(): string {
|
||||
const systemRoot = process.env.SystemRoot || process.env.WINDIR;
|
||||
if (systemRoot) {
|
||||
const candidate = path.join(
|
||||
systemRoot,
|
||||
"System32",
|
||||
"WindowsPowerShell",
|
||||
"v1.0",
|
||||
"powershell.exe",
|
||||
);
|
||||
if (fs.existsSync(candidate)) return candidate;
|
||||
}
|
||||
return "powershell.exe";
|
||||
}
|
||||
|
||||
export function getShellConfig(): { shell: string; args: string[] } {
|
||||
if (process.platform === "win32") {
|
||||
// Use PowerShell instead of cmd.exe on Windows.
|
||||
@@ -8,7 +25,7 @@ export function getShellConfig(): { shell: string; args: string[] } {
|
||||
// When Node.js spawns cmd.exe with piped stdio, these utilities produce no output.
|
||||
// PowerShell properly captures and redirects their output to stdout.
|
||||
return {
|
||||
shell: "powershell.exe",
|
||||
shell: resolvePowerShellPath(),
|
||||
args: ["-NoProfile", "-NonInteractive", "-Command"],
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user