Crazy-Fool
Crazy-Fool

Reputation: 106

Interactive input in Sublime Text 2

I have written a C program in Sublime Text 2 that uses scanf. But Sublime Text completely ignores that and terminates the program. Can it be configured to run the program in normal Windows cmd window instead of the one in Sublime Text ?

Upvotes: 0

Views: 1688

Answers (1)

MattDMo
MattDMo

Reputation: 102902

A build system like the following should work. Save it as Packages\User\new_C.sublime-build, where Packages is the directory opened by selecting the Preferences -> Browse Packages menu option. With a standard Sublime Text installation (i.e., not a portable install), it is located in your User directory, as AppData\Roaming\Sublime Text 2\Packages.

{
    "cmd": [gcc", "$file", "-o", "$file_base_name"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c",
    "shell": true,

    "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. If you'd like the window to close right away, use /c instead.

Upvotes: 1

Related Questions