Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

c++ - How to run programs in an external console with Sublime Text in Windows system?

I managed to configure Sublime Text 2 for C++ and I can now compile my code (using the MinGW compiler).

Unfortunately, the Sublime Text console can't support any kind of input for C++.

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)

Here's my build configuration:

{
"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"
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try with this:

{
    "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"
}

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...