为 g++ build 设置超时,为 Sublime Text 运行?

Set timeout for g++ build and run for Sublime Text?

本文关键字:Text 运行 Sublime 超时 g++ build 设置      更新时间:2023-10-16

我在 ubuntu 上的 Sublime Text 3 上使用 g++,用于构建和运行我的 c++ 程序。构建系统当前如下所示:

{
"cmd" : ["g++ -std=c++14 -Wall $file_name -o $file_base_name && timeout 4s ./$file_base_name<input.txt>output.txt"], 
"selector" : "source.c",
"shell": true,
"working_dir" : "$file_path",
}

正如您在第一行中看到的,超时设置为 4 秒,但是如果我不小心运行了无限循环,超时不起作用,Sublime 只是挂断。我在这里做错了什么?

这是我的 cpp 构建系统,文本精美。由于它是 mac,我已经安装了 coreutils 并使用了 mac 风格的gtimeout命令。我的设置将在 7 秒后终止程序。

{
"cmd": ["g++ -o ${file_path}/${file_base_name} -lm -std=c++17 $file && gtimeout 7 ${file_path}/${file_base_name} && rm ${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.cpp, source.c++",
// "path": "C:/cygwin64/bin",
"shell": true,
"variants": [
{
"name": "Build",
"cmd": ["g++ -o ${file_path}/${file_base_name} -lm -std=c++17 $file && rm ${file_path}/${file_base_name}"]
}
]

}