Skip to content

Commit 2700e12

Browse files
committed
fix(provider): Windows 上 capture_stdout 的 2>/dev/null 让 mcpp test 根本没跑
Windows 上每道练习都判不出结果,现象是 Provider 报「mcpp test 没有返回 '<test>' 的记录」,看起来像 mcpp 不支持 --message-format json —— 实际是本仓库 Provider 自己的问题。 capture_stdout 无条件给命令尾巴上接 ` 2>/dev/null`。Windows 上 _popen 走的是 cmd.exe,那里没有 /dev/null:cmd 把它当成「重定向到 \dev\null 这个路径」,而 \dev 不存在,于是直接报 The system cannot find the path specified. 并且整条命令根本不执行。mcpp test 一条 JSON 都没吐,解析侧 saw_any 为假,判定 链退化成「没有该测试的记录」,那句「mcpp 可能不支持 --message-format json」的 提示把锅指错了方向。 证据(d2x 的 Win10 / Win11 checker 冒烟实测): 外层 `mcpp run -q -p d2x/buildtools -- check hello-mcpp` 本身跑得通 —— 说明 mcpp 在 PATH 上(不在的话 cmd 会报 'mcpp' is not recognized,是另一句话); 只有内层带 2>/dev/null 的 mcpp test 挂掉。两者唯一的差别就是这个重定向。 空设备在 cmd 下叫 NUL,按平台分开写即可。POSIX 分支拼出的字符串与改前逐字节 相同,linux 行为不变;本地实测 check hello-mcpp 仍是 stage → output(真实编译 错误)→ verdict fail。
1 parent 537321b commit 2700e12

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

d2x/buildtools/src/runner.cppm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ export struct Captured {
3333
// workaround 随之删除。
3434
export Captured capture_stdout(const std::string& cmd) {
3535
Captured result;
36+
// 丢弃 stderr 的写法必须分平台:_popen 走的是 cmd.exe,那里没有
37+
// /dev/null —— `2>/dev/null` 会被当成「重定向到 \dev\null 这个路径」,
38+
// 而 \dev 不存在,cmd 直接报 "The system cannot find the path specified."
39+
// 并且整条命令根本不执行。于是 mcpp test 一条 JSON 都吐不出来,判定链
40+
// 退化成「没有该测试的记录」,Windows 上每道题都卡在这里(d2x 的
41+
// Win10/Win11 checker 冒烟实测)。空设备在 cmd 下叫 NUL。
42+
#ifdef _WIN32
43+
std::string full = cmd + " 2>NUL";
44+
#else
3645
std::string full = cmd + " 2>/dev/null";
46+
#endif
3747

3848
#ifdef _WIN32
3949
FILE* pipe = ::_popen(full.c_str(), "r");

0 commit comments

Comments
 (0)