【问题标题】:Set timeout for g++ build and run for Sublime Text?为 Sublime Text 的 g++ 构建和运行设置超时?
【发布时间】:2020-05-20 05:18:51
【问题描述】:

我在 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 就挂了。我在这里做错了什么?

【问题讨论】:

  • 您找到解决方案了吗?我有同样的问题

标签: c++ g++ sublimetext3 clang++


【解决方案1】:

这是我的崇高文本中的 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}"]
    }
]

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 2023-03-22
    • 2016-05-29
    • 2013-12-17
    • 2014-06-29
    • 1970-01-01
    相关资源
    最近更新 更多