Search code examples
cvisual-studio-codevscode-code-runner

Run a program on cmd right after compilation (Code Runner plugin on vscode)


I installed Code Runner to compile my C code. I want the .exe will be directly opened on my cmd after compiling the program like the way Visual Studio is working.

How can I do that?


Solution

  • as it mentions in the marketplace

    Go to VS Code > Preferences:

    • Then Type: Code Runner

    Code Runner

    You will see Code-Runner: Executor-Map click on Edit in settings.json, You'll see something like this:

    {
        "window.zoomLevel": 0,
        "C_Cpp.updateChannel": "Insiders",
        "[javascript]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode"
        },
        "workbench.iconTheme": "material-icon-theme",
        "editor.suggestSelection": "first",
        "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
        "java.configuration.checkProjectSettingsExclusions": false,
        "explorer.confirmDelete": false,
        "javascript.updateImportsOnFileMove.enabled": "always",
        "explorer.confirmDragAndDrop": false
    }
    

    Then add this below "explorer.confirmDragAndDrop": false, like this:

    {
        "window.zoomLevel": 0,
        "C_Cpp.updateChannel": "Insiders",
        "[javascript]": {
            "editor.defaultFormatter": "esbenp.prettier-vscode"
        },
        "workbench.iconTheme": "material-icon-theme",
        "editor.suggestSelection": "first",
        "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
        "java.configuration.checkProjectSettingsExclusions": false,
        "explorer.confirmDelete": false,
        "javascript.updateImportsOnFileMove.enabled": "always",
        "explorer.confirmDragAndDrop": false,
        "code-runner.executorMap": {
            "javascript": "nodejs",
            "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && start $dir$fileName"
        }
    }
    

    And Congratulations :)