Dust_In_The_Wind
Dust_In_The_Wind

Reputation: 3692

VSCode - C++ code runner doesn't work correctly when code-runner.runInTerminal is enabled

C++ Code Runner in VS Code doesn't seem to be able to build the executable correctly if the "run in terminal" option is set to be true - "code-runner.runInTerminal": true.

By default, the output window is read-only, so if my C++ program has no user input via cin, the code runner is able to build the foo.exe correctly from a foo.cpp file. However, if I add the above configuration to the settings.json file (to enable user-input, more details here), it appears that the .exe executable is not built.

This is the sample code I used -

#include <iostream>
using namespace std;


int main() {
  cout<< "Hello World" << endl;
  return 0;
}

Output -

Successful Execution

[Running] cd "c:\Users\Manish\Documents\Development\Github\HackerRank\C++\" && g++ 1.cpp -o 1 && "c:\Users\Manish\Documents\Development\Github\HackerRank\C++\"1
Hello World

[Done] exited with code=0 in 2.235 seconds

Unsuccessful Execution (same file) -

Manish@manish-lenovo MINGW64 ~/Documents/Development/Github/HackerRank/C++ (master)
$ cd "c:\Users\Manish\Documents\Development\Github\HackerRank\C++\" && g++ 1.cpp -o 1 && "c:\Users\Manish\Documents\Development\Github\HackerRank\C++\"1      
bash: cd: c:\Users\Manish\Documents\Development\Github\HackerRank\C++" && g++ 1.cpp -o 1 && c:UsersManishDocumentsDevelopmentGithubHackerRankC++"1: No such file or directory

Screenshots (if required) -

err4

err3

What's going wrong?

Upvotes: 1

Views: 1637

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409156

The Bash shell which is used to run the program in the second case uses backslash as an escape introducer, much like backslash is used in C++.

In your configuration files you need to use either forward slash as path delimiter, or use double backward slash to escape it.

Upvotes: 1

Related Questions