Code Runner for Visual Studio Code

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.


Comments (12)

  1. You can add Powershell and BAT/CMD files:

    // Set the executor of each language.
    “code-runner.executorMap”: {
    “powershell”: “powershell.exe”,
    “bat”: ” ”

    1. Thanks Christopher! 🙂 I have added support for powershell, bat/cmd and bash/sh in v0.0.3.

    2. Albert says:

      where do i set it from? thanks!

      1. Go to File->Preference->Settings

  2. Jahan says:

    How to run C# script

    1. 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

          "code-runner.defaultLanguage": "csharp"

      #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

  3. Albert don says:

    Hi, where do i add support for languages from.

  4. Leo Rapirap says:

    how do I run C/C++ codes?

    1. Leo Rapirap says:

      Nevermind. I got it already, installed Code Runner then highlight the code and do Run code did it.

  5. Dimas Adnan says:

    can someone help me, i have installed the extension, but i still can’t run my C languange program. it said [Running] cd “c:\Users\DIMAS\Desktop\” && gcc test.c -o test && “c:\Users\DIMAS\Desktop\”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 ?

    1. It is because the path of gcc.exe is not in your PATH environment variable.

Skip to main content