1

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
4

2 回答 2

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

cmdstart命令打开传递给它的命令的新窗口。
请注意,要防止窗口在程序结束时立即关闭,您可以使用 or 结束它们system("pause");getch();或者将 /c 替换为 /k 以保持 cmd 正常运行。

编辑:经过更多的挖掘和调试:

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

我在使用 Java 时遇到了同样的问题,试图创建一个 Run Variant,最终得出了这样的结论:

"variants":
[
    {
        "cmd": ["start", "cmd", "/c", "java $file_base_name & pause"],
        "name": "Run"
    }
]
于 2013-09-08T05:01:07.347 回答
0

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
}
于 2018-02-21T18:09:54.443 回答