0

As you know, you can build a file in Sublime either:

1) Through Ctrl+Shift+B (Build With) -> C++ Single File

2) Through Ctrl+Shift+B (Build With) -> C++ Single File - Run

Via the first option I have no problems: file compiles, Sublime confirms, and I don't experience any problems.

If I do it the second way, Sublime can't stop the build process. Right after I click build, a process '(file_name).exe(32 bit)' on Task Manager is created, but the .exe program never runs automatically from Sublime (I have to run it myself), and Sublime never confirms the build.

How can I fix this?

Here is the sublime-build file:

{
    "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",

    "variants":
    [
        {
            "name": "Run",
            "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
        }
    ]
}
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Please [edit] your question and give the contents of your `.sublime-build` file. – MattDMo Jun 22 '16 at 18:20
  • @MattDMo just did it. –  Jun 23 '16 at 10:00
  • I'm assuming you ran the "Run" variant of the build system? If your program didn't exit normally, Sublime still thinks it's running. Does Windows still think it's running - i.e., does it show up in the Task Manager, or by running `ps -ax | grep programname.exe` from the Cygwin/bash shell, assuming you installed that. If so, try killing all instances through Task Manager (you may need to run it with Admin privileges) or by getting the PID(s) (Process ID) from the `ps` command earlier and running `kill -9 123456` or whatever the PID is. – MattDMo Jun 23 '16 at 16:50
  • @MattDMo thanks for pointing out the "Run" variant. Did a little check and found there is a difference in behaviour from the normal variant. I have reformulated the question from scratch now. –  Jun 23 '16 at 17:24

1 Answers1

0

Try editing the `"Variants" section like so:

"variants":
[
    {
        "name": "Run",
        "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k \"${file_path}/${file_base_name}\""
    }
]

This will start a separate instance of cmd.exe and run your newly-built executable within it. One possible reason your build isn't succeeding is the .exe may be waiting for input, which Sublime's console doesn't allow (it's not a true terminal).

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • you are right, it is waiting for input. i copied the code above, but now this error shows up: "shell_cmd or cmd is required [cmd: None] ..." should i add a system variable cmd to point to cmd? or maybe change the cmd to ComSpec since it already points to the location of cmd.exe? –  Jun 23 '16 at 18:08
  • @devidduma I erroneously removed the square brackets. Take a look at the JSON now and add *that* to the build system. The error has to do with the formatting, not `cmd.exe` itself. `"variants"` is an array, not a dict. – MattDMo Jun 23 '16 at 18:22
  • i did not know i had to install Package Control and PackageResourceViewer to modify the files, i was trying to edit them on my own. Everything works perfectly now, thanks a lot –  Jun 23 '16 at 19:43
  • @devidduma Oh, sorry about that. I assumed since you had the contents of the build file you already had PackageResourceViewer. – MattDMo Jun 23 '16 at 23:18