I am trying to run a simple program "primeRange.cpp" using Code Runner extension available for VSCode.
I have selected my default terminal as git bash in VSCode, but when I hit Run on top right corner, it sends the command to bash to run the program using g++ compiler, but I am getting error as no such file or directory, when there exists a directory with the given name.
How can I fix this?
How can I customize which command to hit on bash when I press run on code runner?
I want to set the command as :
cd "c:\\Users\\Tushar\\Desktop\\contests\\Practice" && g++ primeRange.cpp -o primeRange && "c:\\Users\\Tushar\\Desktop\\contests\\Practice\\primeRange"
OR
cd "c:\Users\Tushar\Desktop\contests\Practice" && g++ primeRange.cpp -o primeRange && "c:\Users\Tushar\Desktop\contests\Practice\primeRange"
If I am executing any one of the above command manually on bash then it's working.
So I basically want to know that how to include the executable filename inside the path as:
"c:\Users\Tushar\Desktop\contests\Practice\primeRange"
instead of after the quotes as :
"c:\Users\Tushar\Desktop\contests\Practice\"primeRange
This is my settings.json.
I have updated the path in settings.json to:
"code-runner.executorMap": {
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && \"./$fileNameWithoutExt.exe\""
},
But now I am getting prompt instead of asking for stdin as given below:
RESOLVED
Fix 1:
Updating code-runner.executorMap property in settings.json as
"code-runner.executorMap": {
"cpp": "cd $dirWithoutTrailingSlash && g++ -std=c++11 $fileName -o $fileNameWithoutExt && ./$fileNameWithoutExt"
}
Fix 2:
Adding another property code-runner.terminalRoot in settings.json as:
"code-runner.terminalRoot": "/"
I was having the same issue for quite some time and after hours of online loitering, I think I found the solution.
Windows and Unix/Linux have different ways of naming the address. To address a folder named my_codes inside the d drive, windows will have the following:-" D:\my_codes ", while Unix / Linux will have something like this-"/D/my_codes/". The difference worth noticing is use of different slashes( '/' & \ ). Unix considers \ as a delimiter. So the address being fed to bash is not actually the correct address for the bash. And that is why it throws the error "No such file or directory".
Did you notice that just before bash threw you the error "No such file or directory", it removed all the backslashes from the address and presented you 'c:UsersTusharDesktopcontestPractice' ?
luckily this issue has already been resolved by "Code Runner" devs.
All you have to do is include the following in the setting.json file:
"code-runner.terminalRoot":"/",
I hope I was of some help. Happy Coding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With