When you use cmd
in a build, you specify an array of strings, with the first one being the thing to run and the remaining being arguments as single strings.
So as defined, your build looks like it will build a thing just fine if the input file has a space in it, because "${file}"
is the full argument, and so is "${file_base_name}.exe"
.
So, I would guess that your original problem is not that it can’t compile the executable, it’s that the last argument in your build is:
“${file_base_name}.exe<inputf.in>outputf.in”
Note that here this is considered to be a single argument, so if your input file has a space in it (say it is my file here.cpp
, then the shell is going to see it as:
my file here.exe<inputf.in>outputf.in
What is that doing? It’s trying to execute a program named my
with the arguments file
and here.exe
. I’m going to guess that’s not what you want or expect.
As mentioned by @deathaxe, you should not be using cmd
with "shell": true
. That indicates that what you’re trying to do is run a shell command, and that is what shell_cmd
is for.
When you use shell_cmd
you enter exactly what you would enter in a terminal, and that includes the fact that in the shell files with spaces are a gigantic pain and you need to wrap them in double quotes.
So, I would try something like this:
{
"shell_cmd": "g++.exe -std=c++17 \"${file}\" -o \"${file_base_name}.exe\" && \"${file_base_name}.exe\" <inputf.in>outputf.in",
"working_dir": "$file_path",
"selector": "source.cpp"
}
This is similar to what @deathaxe shared above, except that shell_cmd
should be a string and (crucially), the quoting on the file base name was not in the correct spot.