如何在 Windows 系统中使用 Sublime Text 在外部控制台中运行程序?
我设法为 C++ 配置了 Sublime Text 2,现在我可以编译我的代码(使用 MinGW 编译器).
I managed to configure Sublime Text 2 for C++ and I can now compile my code (using the MinGW compiler).
很遗憾,Sublime Text 控制台不支持任何类型的 C++ 输入.
Unfortunately, the Sublime Text console can't support any kind of input for C++.
我想在外部控制台(例如 Window 的终端)中打开我编译的程序.我尝试使用call"或c??md"但无法正常工作.(它仍然在控制台中打开文件)
I want to open my compiled program in an external console (Window's terminal for instance). I tried to use "call" or "cmd" but couldn't make it work. (it still opens the file in the console)
这是我的构建配置:
{
"cmd": ["C:\MinGW\bin\mingw32-g++.exe", "-Wall", "-time", "$file", "-o", "$file_base_name"],
"cmd": ["call", "$file"],
"file_regex": "^[ ]*File "(...*?)", line ([0-9]*)",
"working_dir": "${project_path:${folder}}",
"selector": "source.c",
"shell": true,
"encoding": "latin1"
}
推荐答案
试试这个:
{
"cmd": ["C:\Dev-Cpp\bin\mingw32-g++.exe", "-static", "-Wall", "-time", "$file", "-o", "$file_base_name.exe", "&&", "start", "$file_base_name"],
"file_regex": "^[ ]*File "(...*?)", line ([0-9]*)",
"working_dir": "${project_path:${folder}}",
"selector": "source.c",
"shell": true,
"encoding": "latin1"
}
诀窍是使用start"命令执行生成的文件,该命令强制文件在新的 cmd 窗口中打开,并将所有内容放在第一个 cmd 定义中(使用 && 以执行这两个命令),因为如果您定义多个 cmd 数组,它们会覆盖.
The trick is to execute the generated file using the "start" command, which forces the file to open in a new cmd window, and to put everything inside the first cmd definition (using the && in order to execute the two commands), because if you define more than one cmd array, they overwrite.
相关文章