fix(platform): quote cmd.exe command lines
Build & Test / build-and-test (push) Canceled after 0s
VDE Build & Test / build-and-test (push) Canceled after 0s
Build & Test / python-bindings (push) Canceled after 0s

This commit is contained in:
hm
2026-10-28 19:07:59 +08:00
parent ea2cf88bb7
commit d87dbd03ae
+8 -2
View File
@@ -218,14 +218,20 @@ bool read_file_head(const std::string& path, std::size_t max_bytes,
}
int run_command(const std::string& cmd) {
return system(cmd.c_str());
// cmd.exe 对以引号开头的 /C 命令有特殊引号剥离规则;再包一层引号,
// 否则 "C:\path with spaces\tool.exe" ... 会被当成命令名的一部分。
std::string line = cmd;
if (!line.empty() && line.front() == '"') line = "\"" + line + "\"";
return system(line.c_str());
}
int run_command(const std::string& cmd, unsigned timeout_ms) {
if (timeout_ms == 0) return run_command(cmd);
#if defined(VDE_PLATFORM_WINDOWS)
// 用 cmd.exe /C 保留 system() 的 shell 语义(重定向、内建命令等)。
std::string command_line = "cmd.exe /C " + cmd;
std::string command_line = "cmd.exe /C ";
if (!cmd.empty() && cmd.front() == '"') command_line += "\"" + cmd + "\"";
else command_line += cmd;
STARTUPINFOA si{};
si.cb = sizeof(si);
PROCESS_INFORMATION pi{};