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

一曲冷凌霜 提交于 2019-12-11 08:55:06

问题


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

回答1:


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



回答2:


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
}


来源:https://stackoverflow.com/questions/18554858/sublime-text-launch-separate-command-window-c-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!