mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-16 12:30:49 +00:00
@@ -298,11 +298,25 @@ describe("restart-helper", () => {
|
||||
|
||||
await runRestartScript(scriptPath);
|
||||
|
||||
expect(spawn).toHaveBeenCalledWith("cmd.exe", ["/c", scriptPath], {
|
||||
expect(spawn).toHaveBeenCalledWith("cmd.exe", ["/d", "/s", "/c", scriptPath], {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
});
|
||||
expect(mockChild.unref).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("quotes cmd.exe /c paths with metacharacters on Windows", async () => {
|
||||
Object.defineProperty(process, "platform", { value: "win32" });
|
||||
const scriptPath = "C:\\Temp\\me&(ow)\\fake-script.bat";
|
||||
const mockChild = { unref: vi.fn() };
|
||||
vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
|
||||
|
||||
await runRestartScript(scriptPath);
|
||||
|
||||
expect(spawn).toHaveBeenCalledWith("cmd.exe", ["/d", "/s", "/c", `"${scriptPath}"`], {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { DEFAULT_GATEWAY_PORT } from "../../config/paths.js";
|
||||
import { quoteCmdScriptArg } from "../../daemon/cmd-argv.js";
|
||||
import {
|
||||
resolveGatewayLaunchAgentLabel,
|
||||
resolveGatewaySystemdServiceName,
|
||||
@@ -161,7 +162,7 @@ del "%~f0"
|
||||
export async function runRestartScript(scriptPath: string): Promise<void> {
|
||||
const isWindows = process.platform === "win32";
|
||||
const file = isWindows ? "cmd.exe" : "/bin/sh";
|
||||
const args = isWindows ? ["/c", scriptPath] : [scriptPath];
|
||||
const args = isWindows ? ["/d", "/s", "/c", quoteCmdScriptArg(scriptPath)] : [scriptPath];
|
||||
|
||||
const child = spawn(file, args, {
|
||||
detached: true,
|
||||
|
||||
Reference in New Issue
Block a user