vscode-code-runner
vscode-code-runner copied to clipboard
C/C++: Can't compile or run when source file path has space(s)
I created a file
D:\Program\USACO\[C2, S3.2] Magic Square.cpp
But when I compile, some errors occurred:
[Running] cd "d:\Program\USACO\" && g++ [C2, S3.2] Magic Square.cpp -o [C2, S3.2] Magic Square && "d:\Program\USACO\"[C2, S3.2] Magic Square
g++: error: [C2,: No such file or directory
g++: error: S3.2]: No such file or directory
g++: error: Magic: No such file or directory
g++: error: Square.cpp: No such file or directory
g++: error: S3.2]: No such file or directory
g++: error: Magic: No such file or directory
g++: error: Square: No such file or directory
g++: fatal error: no input files
compilation terminated.
OS: Win7 SP1 VSCode: 1.19.3 Runner: 0.8.7 5beeedfa674b330537448162dfe9c2330c7eda50
Same problem. After modifying the configuration as follows:
"code-runner.executorMap": { "cpp": "cd $dir && g++ "$fileName" -o "$fileNameWithoutExt" && $dir$fileNameWithoutExt"}
I can run the first two command successfully, but it won't work for the last command ($dir$fileNameWithoutExt).
Here is the output.
@Michany Try changing $dir$fileNameWithoutExt
to $fileNameWithoutExt
?
@hanghang0702 sorry I'm late, @Michany you forgot the escape characters, @formulahendry it isn't the problem on *nix based system the executable file runs with ./"dir"filename ,
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac \"$fileName\" && java \"./$fileNameWithoutExt\"",
"c": "cd $dir && gcc \"$fileName\" -o \"$fileNameWithoutExt\" && \"./$fileNameWithoutExt\"",
"cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" && \"./$fileNameWithoutExt\"",
"objective-c": "cd $dir && gcc -framework Cocoa \"$fileName\" -o \"$fileNameWithoutExt\" && \"./$fileNameWithoutExt\"",}
I'm not a windows user & I'm not sure if it's going to work on windows (you'll probably need to adjust/change some escape characters or something similar). I really hope they edit & fix it in the upcoming version(s).
Same issue here.
When I run C code in bash terminal. I get this: bash: cd: d:\VscodeProject\C\demo" && gcc file1.c -o file1 && d:VscodeProjectCdemo"file1: No such file or directory Obviously, the last command is not recognised correctly. How to fix it?
Hello!
I have a same problem in Mac OS X. Some solution to this bug? If I rename Example 1.cpp to Example1.cpp or Example_1.cpp then, it works ok...
Thank you!
If you are using Windows, try configuring settings like this:
"code-runner.executorMap": {
"cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && & \"$dir$fileNameWithoutExt.exe\""
}
Pay attention to the extra '&'
character.
If you are using Unix based system, try this (I haven't tested, but I think this would work):
"code-runner.executorMap": {
"cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" && \"$dir$fileNameWithoutExt\""
}
Hello, I have the same problem. I'm using Windows, I'm trying to run a simple C++ program, I don't have spaces anywhere in the path or file name.
[Running] cd "c:\Users\Guillaume\Desktop\" && g++ test.cpp -o test && "c:\Users\Guillaume\Desktop\"test
g++: error: test.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
If I copy the command as is, and paste it in a cmd.exe then it works without problem :/
I made changes as suggested by others but nothing worked.
EDIT: Solved! Here is how, maybe it will help others :
"code-runner.executorMap": {
"cpp": "cd $dir && g++ $dirWithoutTrailingSlash\\$fileName -o $fileNameWithoutExt && $fileNameWithoutExt"
}
hello there... i am not able to find code-runner,executorMap anywhere where exactly do i paste this piece of code ... in settings.json ? ... it did not work be pasting the code there ... :(
hello there... i am not able to find code-runner,executorMap anywhere where exactly do i paste this piece of code ... in settings.json ? ... it did not work be pasting the code there ... :(
Yes in settings.json.
I finally used this command instead:
"cpp": "cd $dir ; g++ $fileName -o $fileNameWithoutExt.exe ; .\\$fileNameWithoutExt.exe"
Here is extract of my settings.json :
"c-cpp-compile-run.cpp-compiler": "C:\\MinGW\\bin",
"window.zoomLevel": -1,
"code-runner.executorMap": {
//"javascript": "node",
//"php": "C:\\php\\php.exe",
//"python": "python",
//"perl": "perl",
//"ruby": "C:\\Ruby23-x64\\bin\\ruby.exe",
//"go": "go run",
//"html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
//"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
//"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir ; g++ $fileName -o $fileNameWithoutExt.exe ; .\\$fileNameWithoutExt.exe"
},
"C_Cpp.default.cppStandard": "c++20",
"C_Cpp.default.cStandard": "c11",
I believe I am also having this issue. Are there any plans on resolving it? Here are my results:
$ cd "c:\Users\Jacob Armiger\Documents\cpp_files\" && g++ hello.cpp -o hello && "c:\Users\Jacob Armiger\Documents\cpp_files\"hello bash: cd: too many arguments
Hello, after trying a lot of time I found the solution, hope this will help others
"cpp": "cd $dir && g++ "$fileName" -o "$fileNameWithoutExt" && .\"$fileNameWithoutExt"",
Hello, after trying a lot of time I found the solution, hope this will help others
"cpp": "cd $dir && g++ "$fileName" -o "$fileNameWithoutExt" && ."$fileNameWithoutExt"",
Where to add this?? IN settings.json file in .vscode?? or somewhere else?
-->Yeah you need to copy that on your settings.json (exactly in your executor map) on vscode, i’m going to attach a photo
Windows Guys! Just Copy Past This to your settings.json file
I did a lot of research and this will surely work
"code-runner.executorMap": {
"cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" && \"$fileNameWithoutExt\""
},
If you are using Windows, try configuring settings like this:
"code-runner.executorMap": { "cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && & \"$dir$fileNameWithoutExt.exe\"" }
Pay attention to the extra
'&'
character.If you are using Unix based system, try this (I haven't tested, but I think this would work):
"code-runner.executorMap": { "cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" && \"$dir$fileNameWithoutExt\"" }
this worked for me. I Am now able to compile and run c cpp and java files('&' is not needed in java though if anyone is wondering)
If you are using Windows, try configuring settings like this:
"code-runner.executorMap": { "cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && & \"$dir$fileNameWithoutExt.exe\"" }
Pay attention to the extra
'&'
character.If you are using Unix based system, try this (I haven't tested, but I think this would work):
"code-runner.executorMap": { "cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt\" && \"$dir$fileNameWithoutExt\"" }
This solution works!! Finally my c program could be compiled and run. Thanks!
It really helped, Thank You! I am on Windows
PLEASE HELP!!!😭 I'm getting the same error.
{
"atomKeymap.promptV3Features": true,
"editor.multiCursorModifier": "ctrlCmd",
"editor.formatOnPaste": true,
"python.pythonPath": "C:\\Users\\ABHISHEK\\anaconda3\\python.exe",
"java.home": "C:\\Program Files\\Java\\jdk-12.0.2",
"java.help.firstView": "gettingStarted",
"workbench.iconTheme": "vscode-icons",
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"java.semanticHighlighting.enabled": true,
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"python.jediEnabled": false,
"python.dataScience.sendSelectionToInteractiveWindow": true,
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"python.languageServer": "Microsoft",
"files.associations": {
"*.cpp": "cpp"
},
"C_Cpp.updateChannel": "Insiders",
"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.exe\" && & \"$dir$fileNameWithoutExt.exe\"",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir $fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"scheme": "csi -script",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runhaskell",
"nim": "nim compile --verbosity:0 --hints:off --run",
"lisp": "sbcl --script",
"kit": "kitc --run",
"v": "v run",
"sass": "sass --style expanded",
"scss": "scss --style expanded",
"less": "cd $dir && lessc $fileName $fileNameWithoutExt.css"
},
"window.zoomLevel": 0,
"files.autoSave": "onFocusChange",
"diffEditor.ignoreTrimWhitespace": false,
"[cpp]": {
"editor.wordBasedSuggestions": false,
"editor.suggest.insertMode": "replace",
"editor.semanticHighlighting.enabled": true
},
"code-runner.runInTerminal": true,
"code-runner.saveAllFilesBeforeRun": true,
"settingsSync.ignoredSettings": [
"-java.configuration.runtimes"
],
"liveServer.settings.donotShowInfoMsg": true,
"java.refactor.renameFromFileExplorer": "autoApply",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"eslint.codeAction.showDocumentation": {
"enable": true
},
"git.autofetch": true,
"vsicons.dontShowNewVersionMessage": true,
}
This and still I'm getting the same error.
And my environment variables :
And just in case if anyone has doubts about my files and such...
@formulahendry @HeyJayant @kaushik-rishi
@tripathi-abhishek use this
In case you run into issues with a bash error like "bash: cd: too many arguments"
Fixed by:- Go to visual studio code settings for code runner and replace cpp key value pair in code-runner.executorMap with the following :- "code-runner.executorMap": { "cpp": "g++ $fileName -o $fileNameWithoutExt.exe && './$fileNameWithoutExt.exe'" }
Screenshot:-
replace your cpp key value pair with the below mentioned code in "code-runner.executorMap" like:-
@VipulKhandelwal1999 thanks this worked!
@ushakhanal read my comments. I have already explained what to do in case of "too many arguments" error.
For windows in settings .json change cpp to the following:
"code-runner.executorMap": { "cpp": "g++ $fileName -o $fileNameWithoutExt.exe && './$fileNameWithoutExt.exe'", }
For windows in settings .json change cpp to the following:
"code-runner.executorMap": { "cpp": "g++ $fileName -o $fileNameWithoutExt.exe && './$fileNameWithoutExt.exe'", }
this works for me
Thank you very much, I was using the same .json as you suggested.
Simple open the code runner configuration by search in settings code runner and under extensions selecting it then scroll and click on edit setting.json change the cpp configuration as "code-runner.executorMap": { "cpp": "cd $dir && g++ "$fileName" -o "$fileNameWithoutExt.exe" && "$fileNameWithoutExt.exe"" }
hello there... i am not able to find code-runner,executorMap anywhere where exactly do i paste this piece of code ... in settings.json ? ... it did not work be pasting the code there ... :(
Yes in settings.json.
I finally used this command instead:
"cpp": "cd $dir ; g++ $fileName -o $fileNameWithoutExt.exe ; .\\$fileNameWithoutExt.exe"
Here is extract of my settings.json :
"c-cpp-compile-run.cpp-compiler": "C:\\MinGW\\bin", "window.zoomLevel": -1, "code-runner.executorMap": { //"javascript": "node", //"php": "C:\\php\\php.exe", //"python": "python", //"perl": "perl", //"ruby": "C:\\Ruby23-x64\\bin\\ruby.exe", //"go": "go run", //"html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"", //"java": "cd $dir && javac $fileName && java $fileNameWithoutExt", //"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", "cpp": "cd $dir ; g++ $fileName -o $fileNameWithoutExt.exe ; .\\$fileNameWithoutExt.exe" }, "C_Cpp.default.cppStandard": "c++20", "C_Cpp.default.cStandard": "c11",
Thank you. Your executorMap worked for my cpp files in code runner but I copied the same executorMap for c programs and it isnt working.
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir ; g++ $fileName -o $fileNameWithoutExt.exe ; .\\$fileNameWithoutExt.exe",
I am getting this error
PS C:\Users\jithin_d_mathew\Desktop\stufff\CC++> cd "c:\Users\jithin_d_mathew\Desktop\stufff\CC++\" && gcc jhbuhb.c -o jhbuhb && "c:\Users\jithin_d_mathew\Desktop\stufff\CC++\"jhbuhb
At line:1 char:52
+ cd "c:\Users\jithin_d_mathew\Desktop\stufff\CC++\" && gcc jhbuhb.c -o ...
+ ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:78
+ ... n_d_mathew\Desktop\stufff\CC++\" && gcc jhbuhb.c -o jhbuhb && "c:\Use ...
+ ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:81
+ ... .c -o jhbuhb && "c:\Users\jithin_d_mathew\Desktop\stufff\CC++\"jhbuhb
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expressions are only allowed as the first element of a pipeline.
At line:1 char:128
+ ... .c -o jhbuhb && "c:\Users\jithin_d_mathew\Desktop\stufff\CC++\"jhbuhb
+ ~~~~~~
Unexpected token 'jhbuhb' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine
EDIT
I managed to do it for C with this
"c": "cd $dir ; gcc $fileName -o $fileNameWithoutExt.exe ; .\\$fileNameWithoutExt.exe",
It works for me!
"c": "gcc $fullFileName -o ./out/$fileNameWithoutExt && ./out/$fileNameWithoutExt",
"cpp": "g++ $fullFileName -o ./out/$fileNameWithoutExt && ./out/$fileNameWithoutExt",