2

I'm using the Code Runner extension in vs code,

I want to change the output directory of compiled-cpp (.exe) files but I don't know what variable-name I will type in

  • my "settings.json" file :
"code-runner.executorMap": {
    
        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", // <- this

Is anyone know where the variable-name documentation for this case ? anyway sorry for my bad english

I've tried to implement from https://code.visualstudio.com/docs/editor/variables-reference like this :

"cpp": "cd $dir && g++ $file -o $workspaceFolder\\C++\\bin\\$fileNameWithoutExt && $workspaceFolder\\C++\\bin\\$fileNameWithoutExt",

and I got : Unexpected token '\C++\bin\stringComparison' in expression or statement

starball
  • 20,030
  • 7
  • 43
  • 238
Bongcoy
  • 33
  • 3

2 Answers2

3

formulahendry/vscode-code-runner: Code Runner for Visual Studio Code (github.com)

Supported customized parameters

  • $workspaceRoot: The path of the folder opened in VS Code
  • $dir: The directory of the code file being run
  • $dirWithoutTrailingSlash: The directory of the code file being run without a trailing slash
  • $fullFileName: The full name of the code file being run
  • $fileName: The base name of the code file being run, that is the file without the directory
  • $fileNameWithoutExt: The base name of the code file being run without its extension
  • $driveLetter: The drive letter of the code file being run (Windows only)
  • $pythonPath: The path of Python interpreter (set by Python: Select Interpreter command)

Please take care of the back slash and the space in file path of the executor

  • Back slash: please use \\
  • If there ares spaces in file path, please use \" to surround your file path
0

Open Visual Studio Code -> Setting -> Upper right corner -> Press open setting.json and then edit the code runner executorMap "cpp" with this command.

"code-runner.executorMap": {
        "cpp": "cd $dir && g++ -std=c++17 \"$fileName\" -o \"$fileNameWithoutExt.o\" && $dir\"$fileNameWithoutExt.o\"",
}
Badhan Sen
  • 617
  • 1
  • 7
  • 18