Create_The_World
Create_The_World

Reputation: 5

This build system wont work, sublime text 3

I have a build system to work with c++. I have MinGW installed, I have it in the path, yet when I run it (ctrl + b), in the command prompt it show:

'E:\Projects\C++ Projects' is not recognized as an internal
 or external command, operable program or batch file.

I dont get it! I had this working a couple of months before and now when I tried it on my new PC it doesn't work. I have everything set up exactly the same. Here is the sublime-build JSON code if it helps:

{
    "cmd": ["C:\\MinGW\\bin\\g++", "${file}", "-o", "${file_path}\\${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "shell": "true",
    "variants":
    [
        {
            "name": "Run",
            "cmd": ["start", "cmd.exe", "@cmd", "/k", "${file_path}\\${file_base_name}"]
        }
    ]
}

Upvotes: 0

Views: 365

Answers (1)

OdatNurd
OdatNurd

Reputation: 22791

I can see only two problems with this build system as it's laid out here that might stop it from being able to run your program.

The first is that in the Run variant, the path to the program to be run is specified as:

"${file_path}\\${file_base_name}"

Since the file is JSON, the \\ is converted into a single \ character when the JSON is loaded, and then when Sublime runs the command, it sees \$ which it takes to mean that you want a literal $ character, and so the ${file_base_name} does not expand out.

For example, on my machine I see this error:

'C:\Users\tmartin\Desktop${file_base_name}' is not recognized 
as an internal or external command, operable program or 
batch file.

The error that you're seeing doesn't include that, which would make me think that either this isn't the Build that's actually selected, or the build that you pasted in here isn't entirely the same as the one that you're actually using.

In any case, the build need to have the path separators doubled up in that particular case:

"${file_path}\\\\${file_base_name}"

Now the first \\ converts to \ on load, as does the second, and then Sublime sees \\$ and correctly assumes you meant to put a path separator followed by a variable example, which converts the error message to this instead:

'C:\Users\tmartin\Desktop\test' is not recognized as an 
internal or external command, operable program or batch file.

The second "Problem" is that the Run variant doesn't try to compile the program, it only tries to run it. That means that until you've built it for the first time, when you try to run it Windows can't find it and would give you this error.

As such, if you haven't already tried it, you should switch to the normal variant first and compile your program, and then switch to the Run variant and try again.

That said, the error message that you're getting about Windows not being able to find the program only makes sense if the program you're trying to run is named C++ Projects.

That sounds more like the name of the folder that your projects would be stored in than the name of a project itself, which would also make me think that you may not be using the build that you think you are.

To be absolutely sure, I would try renaming the sublime-build file to something definitely distinct and then selecting it from the build menu under that name.

Upvotes: 2

Related Questions