Sublime Text launch separate command window (C/C++)

2.8k Views Asked by At

I am trying to do all the programs in Programming in C by Stephen G. Kochan as an exercise and to familiarize myself with some of the finer details (I didn't go to school for computer science) of C (on a Windows 8 machine).

A lot of the book is simple programs and I'd like to enter the programs with Sublime Text (as opposed to Code::Blocks, which I have been using with openFrameworks). Is there an easy way to launch a separate command window for a program after it is compiled.

It's kind of hacky, but I changed the "run" version of build to launch the compiled program

"cmd": ["${file_base_name}.exe"]

but apparently, the Sublime Text documentation says that GUI's are suppressed.

What I want to do is launch a separate command prompt window. The primary reason is that scanf does not halt for input. Let me know if there is a quick workaround:

  • some workaround in Sublime Text ( a setting I'm not aware of)
  • how to change the build file to launch an actual window
  • some way to easily launch a separate window in C
2

There are 2 best solutions below

0
On
{
    "cmd": ["start", "cmd", "/c $file_base_name.exe"],
    "selector": "text.c",
    "shell": "true"
}

The cmd start command opens a new window of the command passed to it.
Note that to keep the window from closing immediately at the end of your programs, you'll have end them with system("pause"); or getch();, or replace /c with /k to keep cmd up.

EDIT: after more digging and debugging:

"cmd": ["start", "cmd", "/c", "$file_base_name.exe & pause"]  

I had the same issue with Java, trying to create a Run Variant, and eventually came out with this:

"variants":
[
    {
        "cmd": ["start", "cmd", "/c", "java $file_base_name & pause"],
        "name": "Run"
    }
]
0
On

https://github.com/guilherme-p/Sublime-Build-Systems/blob/master/myC.sublime-build

{
    "working_dir" : "$file_path",
    "cmd": ["start", "cmd", "/k gcc $file_base_name.c -o $file_base_name.exe && $file_base_name.exe"],
    "selector" : "source.c",
    "shell" : true
}