Download: Code Runner for Visual Studio Code
I have been developing WordPress as well as writing the best language of the world for over 1 year. Sometimes, I write or get a small piece of PHP code and want to run it immediately to see whether it works as expected or how it works. Unfortunately, I always forget whether it is php -f
or php -r
to run a php file or php code snippet. I need to Google it and then open a shell and then type the command and then copy/paste the code snippet and then run it. Therefore, I decide to write this extension.😁
Current version supports JavaScript, PHP, Perl, Python, Ruby and Go. And more language support is coming soon. (Update: In v0.0.2, Lua and Groovy are supported. In v0.0.3, powershell, bat/cmd and bash/sh are supported. For more updates, please see the Change Log.)
The most useful point of this extension is that you could select some lines of code and then kick off the run immediately. To implement this, I just need to create a temp file with the selected code, then call the corresponding interpreter to run the file. All languages should work well without any special handling, except PHP and Python. 😦 Yes, you know. For PHP, the PHP file need to start with <?php
. But how about the selected php code snippet? They may not have the <?php
at the beginning. No problem, just add it if there’s no <?php
to resolve this. And for Python? 🙂 Currently, I haven’t dealt with it because I do not want to do too much special handling for its amazing code style. But if users really want the full support for Python, I may consider supporting it as well.
You can add Powershell and BAT/CMD files:
// Set the executor of each language.
“code-runner.executorMap”: {
“powershell”: “powershell.exe”,
“bat”: ” ”
}
LikeLike
Thanks Christopher! 🙂 I have added support for powershell, bat/cmd and bash/sh in v0.0.3.
LikeLike
where do i set it from? thanks!
LikeLike
Go to File->Preference->Settings
LikeLike
How to run C# script
LikeLike
Hi Jahan, first, you need to install scriptcs. Then there will be three ways to run C# script:
#1 use shortcut Ctrl+Alt+J, or press F1 and then select/type Run By Language, then type the language csharp. You could refer to below gif which is to run pyhton
#2 Set default language as csharp, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code
#3 If you have installed C# extension, you could open a .cs or .csx file, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code
LikeLike
Hi, where do i add support for languages from.
LikeLike
Here to add more languages support: https://github.com/formulahendry/vscode-code-runner/blob/master/package.json#L94
LikeLike
how do I run C/C++ codes?
LikeLike
Nevermind. I got it already, installed Code Runner then highlight the code and do Run code did it.
LikeLike
can someone help me, i have installed the extension, but i still can’t run my C languange program. it said [Running] cd “c:UsersDIMASDesktop” && gcc test.c -o test && “c:UsersDIMASDesktop”test
‘gcc’ is not recognized as an internal or external command,
operable program or batch file.
[Done] exited with code=1 in 0.123 seconds
i had no idea what i will do with the setting, so i’m still not adding anything to my preference settings yet. Can someone help me ?
LikeLike
It is because the path of gcc.exe is not in your PATH environment variable.
LikeLike
how to run python code
LikeLike
You could simply follow the instruction: https://github.com/formulahendry/vscode-code-runner#usages
Just make sure Python is set in PATH environment variable
LikeLike
По моему мнению Вы допускаете ошибку. Могу отстоять свою позицию. Пишите мне в PM, обсудим.
LikeLike