Cretu Eusebiu
Cretu Eusebiu

Reputation: 147

Run program in cmd mode after building from Sublime Text 2

I'm using Sublime Text 2 with MinGW as a build system to compile my c++ programs. I have the following build added to my Sublime:

{
    "cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],
    "path": "C:\\Program Files (x86)\\MinGWStudio\\MinGW\\bin\\"
}

Now I want to run the program that I've just compiled in a cmd window (not in the Sublime console) What should I add to that command ? Thank you.

Upvotes: 3

Views: 9194

Answers (2)

Wouter Bovelander
Wouter Bovelander

Reputation: 33

For those trying this on MacOs (High Sierra) and Sublime 2, you might want to consider the next string in your build system:

{
    "cmd": ["make", "${file_base_name}"],
    "selector" : "source.c",
    "variants": [

        {   
            "cmd": ["/Applications/vice/x64sc.app/Contents/MacOS/x64sc $file_base_name"],
            "shell": true,
            "name": "Run"
        }
    ]   
}

This example will start Vice (the C64 emulator) installed in its specific location, which takes the file base name as an argument. Please note that I do not use "start", "cmd" or "/k".

Upvotes: 0

MattDMo
MattDMo

Reputation: 102902

A build system like the following will run your program in a new cmd window after you build it:

{
    "cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],
    "path": "C:\\Program Files (x86)\\MinGWStudio\\MinGW\\bin\\",

    "variants": [

        {   
            "cmd": ["start", "cmd", "/k", "$file_base_name"],
            "shell": true,
            "name": "Run"
        }
    ]
}

The "Run" name has special significance, it means that when you select this build system as your default, hitting CtrlB will compile your program, and then hitting CtrlShiftB will execute it. start is the command to start running a separate process, cmd is short for cmd.exe, the Windows command line program, and the /k option keeps the resulting window open after your program exits so you can see its output, run additional commands, or what have you.

Upvotes: 8

Related Questions