I'm using the Code Runner for [VSCode][2] (Visual Studio Code) and I'm trying to change the run command for C++
.
I have the following setting in my settings.json file:
// Set the executor of each language.
"code-runner.executorMap": {
// ...
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
// ...
}
Then when I press CTRL SHIFT P
and press enter on Run Code
to run my current C++ file, it produces the following command to be ran:
cd "c:\C++\" && g++ main.cpp -o main && "c:\C++\"main
But then the output of the command is:
bash: cd: c:\C++" && g++ main.cpp -o main && c:C++"main: No such file or directory
This is because as you can see in the command being run, it's trying to CD to "c:\C++\"
but the \
characters are not being escaped and it causes the command to fail.
If the command had all the \
characters escaped to look like "c:\\C++\\"
, it would run correctly.
I am using the git bash console for my integrated terminal.
How can I fix this issue and escape the path's retreived from the $dir
variable in my settings.json
file?
Try out the $dirWithoutTrailingSlash variable instead of $dir.
If that doesn't work, you can try making your own variables in
codeManager.js
located in%VSCODE_INSTALL%\Data\code\extensions\formulahendry.coderunner-%VERSION%\out\src\
.Add entries to the
placeholders
array located near line # 246. For example:which I used to replace
because I couldn't use variables with explicit quotes in classpaths. You can also define your own function return values (like getCodeFileDirWithoutTrailingSlash) with regex right above it (circa line #222).