一、C编译系统配置文件如下:
{
"shell":true,
"cmd": "cmd /c g++ -fexec-charset=GBK ${file} -o ${file_path}/${file_base_name} && start cmd /c \"${file_path}/${file_base_name} && pause\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants":
[
{
"name": "Run",
"cmd": "cmd /c && start cmd /c \"${file_path}/${file_base_name} && pause\""
}
]
}
其中决定最终输出窗口是cmd的关键语句为:
"cmd": "cmd /c g++ -fexec-charset=GBK ${file} -o ${file_path}/${file_base_name} && start cmd /c \"${file_path}/${file_base_name} && pause\"",
这句语句包含了编译文件并运行生成的二进制文件两个过程。
假设要编译的文件是test.c文件,路径为D:\code\test.c,则以上命令的效果同以下手动在cmd窗口敲的命令等同:
g++ -fexec-charset=GBK D:\code\test.c -o D:\code\test && D:\code\test && pause
解释:
1)-fexec-charset=GBK:为了防止cmd窗口输出中文乱码
2)start cmd /c:重新启动一个cmd窗口
二、python编译系统配置文件如下:
{
"encoding":"cp936",
"shell":true,
"cmd": "start cmd /k python -u ${file}",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}