Can I use multiple different commands for a single file type in coderunner?
"code-runner.executorMap": {
"cpp": "cd $dir && g++ -Wall -Wextra -O2 -std=c++14 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
Coderunner has a command to run .cpp code, but if I want to use another command, such as adding " < input.txt", I would have to go to settings.json to change it. Is there a way to set up multiple commands on vscode for a single kind of file so I can just simply switch without having to change settings.json?
do you know?
how many words do you know
See also questions close to this topic
-
Is it possible to use input variables in keybindings in VS Codium?
In Visual Studio Codium I want to define a command that has a variable parameter.
I want the IDE to open specific file, which name is written in another file. Assume I have the following project structure:
/home/user/myproject/ /home/user/myproject/dir1/ /home/user/myproject/dir1/problem1.py /home/user/myproject/dir1/problem2.py /home/user/myproject/dir2/problem1.py ... /home/user/myproject/pointer.txt
The
pointer.txt
contains path to the file I want to work on. For example, it contains:dir1/problem1
.I have read the documentation here. Now I created the following construction:
keybindings.json
:{ "key": "numpad3", "command": "htmlRelatedLinks.openFile", "args": { "file": "${workspaceFolder}/${input:mycatinput}.py", "method": "vscode.open", "viewColumn": 2, } },
tasks.json
:{ "version": "2.0.0", "tasks": [ { "label": "mycat", "type": "shell", "command": "cat /home/user/myproject/pointer.txt" }, ], "inputs": [ { "id": "mycatinput", "type": "command", "command": "workbench.action.tasks.runTask", "args": "mycat" } ] }
But when I press numpad3, I get an error notification with text:
Unable to open '${input:mycatinput}.py': File not found.
Am I missing something? How do I specify a variable in keybindings.json command, which itself is a result of another command (a shell command, not a vscode command).
-
How do I set the default c# file in my Visual Studio Code c# Project?
I am new to using Visual Studio Code. I have always used Visual Studio IDE in Windows. I am trying to run a simple Hello World Program on Mac with VS Code. I ran the following command
dotnet new console
which successfully created the csProj file and Program.cs file with the code
Console.WriteLine("Hello, World!");
Now by issuing dotnet run command I can get the output from this Program as well. But I have a different cs file called "Hello.cs" in the same Project location. How do I get the Hello.cs to run instead of the default "Program.cs" created bydotnet new console
command. I tried giving the following property group in the .csproj file but VS Code reports error this is reserved property.<PropertyGroup><StartupObject>Hello.HelloWorld</StartupObject></PropertyGroup>
Is there another way to choose your default startup CS File if you have multiple CS files in your Project.
-
How to set breakpoint when I use vscode Code Runner extension to execute typescript?
Here is my source code: https://github.com/kody-liou/code-runner-set-breakpoint
I use the extension "Code Runner" to execute my typescript file. I set a breakpoint then I press the "Run Code". The breakpoint was not working. I expect the breakpoint should be hit.
Here is my .vscode/settings.json
{ "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "code-runner.executorMap": { "typescript": "node_modules/.bin/ts-node-dev --inspect --" }, }
-
What is the correct command to invoke nodemon right after tsc starts listening for any changes
I am learning TypeScript and need to invoke
nodemon
right aftertsc
starts listening for any changes in.ts
files.Usually I can do with two terminal windows as follows:
- First window:
tsc -w filename.ts
- Second window:
nodemon filename.js
The above approach seems to me a bit cumbersome so I want to automate using shortcut
ctrl+alt+n
(provided by Code Runner extension):"code-runner.executorMap": { "typescript": "tsc -w $fileNameWithoutExt.ts & nodemon $fileNameWithoutExt.js" }
Unfortunately, only
tsc
is invoked and it starts listening,nodemon
is not invoked.Question
What is the correct method to invoke
nodemon
right aftertsc
starts listening? - First window:
-
Running Python3 script in VS Code doesn't recognize environment variables unless running debugger (MacOS)
To clarify I set up the .env file for environment variables correctly and when I run the code either via the built-in terminal (default play button) or to output via the Code Runner plugin, the attempts to grab those environment variables always end up null. However, the same thing works when running via debugger with no problem.
This has been a relatively widely experienced issue ~3 years ago from my research. I followed the official documentation exactly and I know I formatted the .env file right because it works with the debugger.
I checked all posts I found across StackOverflow and the VS-Code GitHub trying dozens of solutions. A lot of these mentioned solutions didn't work for me or are out of date for Monterey. I've tried several things from these and on my own including:
- Disable Code Runner
- Rename file to
dev.env
and others, while reflecting Env File path in VS Code settings - Placing .env file in vscode and .venv folders while reflecting in path
- I've tried a series of commands in the settings JSON I've found online. Sorry, I'm not going to be more specific, I've tried so many.
- I haven't tried installing environment variables to the python path yet, something I'm unclear on how to do if it makes sense to do so.
I'm using the last-gen of Intel Mac running the latest macOS Monterey 12.3.1, the latest VS Code 1.66.2, and the latest version of Python 3.10.4. Currently, I have the default Env File path set:
${workspaceFolder}/.env
and a file named.env
in the workspace folder.Unless I'm missing something I'm not sure how this would have gone unresolved for this long and/or I'm missing the solution. Regardless of what I've tried, I'd like to know what the best/go-to solution is for almost everyone faced with this problem. Thank you for your help.
-
visual studio code how to run to show the output only
I just download visual studio code to do my college project in C language. I already download all the necessary extensions to run the code but when I want to run the code option only the terminal will send me this
PS C:\Users\User\Documents\c test> cd "c:\Users\User\Documents\c test" ; if ($?) { g++ Hello world.c -o Hello world } ; if ($?) { .\Hello world }
cc1plus.exe: fatal error: world.c: No such file or directory compilation terminated.but if I run it in debug C\C++ file or Run C\C++ file the code output will show can you help me to make the terminal will show the output only
-
Why does CodeRunner not recognize my path in VS Code? Using WSL
I'm brand new to programming and I'm getting my environment set up. I'm using CodeRunner on VS Code to get my javascript outputs. In each output though, I'm getting a frustrating error:
\\wsl.localhost\Ubuntu\home\a\prep-work\Javascript\Udemy\JS3_Conditional CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory.
I couldn't find any answers on the related CodeRunner Github. I'm pretty sure it's some error with path naming but a few hours of searching and playing with CodeRunner settings have me ready to give up. Any help would be greatly appreciated, thanks!
-
Error in terminal when trying to run code in VSCode
I'm relatively new to using IDEs and recently started using VSCode for class. I'm using the Code Runner extension and working on a Mac. Whenever I go to run a piece of code I receive the following message in my terminal:
The default interactive shell is now zsh. To update your account to use zsh, please run
chsh -s /bin/zsh
. For more details, please visit https://support.apple.com/kb/HT208050.Could someone help explain what exactly this message means? I think for class we want to use the Bash shell so I'm hesitant to make any changes to the current settings but I don't want it to interfere with my ability to run/test code.