How to compile and run C files from within Notepad++ using NppExec plugin?

前端 未结 10 1434
北荒
北荒 2020-11-30 00:45

How can I configure the NppExec plugin for Notepad++?

I would like NppExec to compile my C files, run them, and show their output, all within Notepad++.

相关标签:
10条回答
  • 2020-11-30 01:12

    I've made a single powerfull script that will:

    -Compile and run multi language code like C, C++, Java, Python and C#.
    -Delete the old executable before compiling code.
    -Only run the code if it's compiled successfully.

    I've also made a very noob friendly tutorial Transform Notepad++ to Powerful Multi Languages IDE which contains some additional scripts like to only run or Compile the code, run code inside CMD etc.

    npp_console 1               //open console
    NPP_CONSOLE -               //disable output of commands
    npe_console m-              //disable unnecessary output
    con_colour bg= 191919 fg= F5F5F5    //set console colors
    npp_save                //save the file
    cd $(CURRENT_DIRECTORY)         //follow current directory
    NPP_CONSOLE +               //enable output
    IF $(EXT_PART)==.c GOTO C       //if .c file goto C label
    IF $(EXT_PART)==.cpp GOTO CPP       //if .cpp file goto CPP label
    IF $(EXT_PART)==.java GOTO JAVA     //if .java file goto JAVA label
    IF $(EXT_PART)==.cs GOTO C#     //if .cs file goto C# label
    IF $(EXT_PART)==.py GOTO PYTHON     //if .py file goto PYTHON label
    echo FILE SAVED
    GOTO EXITSCRIPT             // else treat it as a text file and goto EXITSCRIPT
    //C label
    :C                                                                  
    cmd /C if exist "$(NAME_PART).exe" cmd /c del "$(NAME_PART).exe"//delete existing executable file if exists
    gcc "$(FILE_NAME)" -o $(NAME_PART)              //compile file
    IF $(EXITCODE) != 0 GOTO EXITSCRIPT             //if any compilation error then abort
    echo C CODE COMPILED SUCCESSFULLY:              //print message on console
    $(NAME_PART)                                            //run file in cmd, set color to green and pause cmd after output
    GOTO EXITSCRIPT                         //finally exits
    
    :CPP
    cmd /C if exist "$(NAME_PART).exe" cmd /c del "$(NAME_PART).exe"
    g++ "$(FILE_NAME)" -o $(NAME_PART)
    IF $(EXITCODE) != 0 GOTO EXITSCRIPT
    echo C++ CODE COMPILED SUCCESSFULLY:
    $(NAME_PART)
    GOTO EXITSCRIPT
    
    :JAVA
    cmd /C if exist "$(NAME_PART).class" cmd /c del "$(NAME_PART).class"
    javac $(FILE_NAME) -Xlint
    IF $(EXITCODE) != 0 GOTO EXITSCRIPT
    echo JAVA CODE COMPILED SUCCESSFULLY:
    java $(NAME_PART)
    GOTO EXITSCRIPT
    
    :C#
    cmd /C if exist "$(NAME_PART).exe" cmd /c del "$(NAME_PART).exe"
    csc $(FILE_NAME)
    IF $(EXITCODE) != 0 GOTO EXITSCRIPT
    echo C# CODE COMPILED SUCCESSFULLY:
    $(NAME_PART)
    GOTO EXITSCRIPT
    
    :PYTHON
    echo RUNNING PYTHON SCRIPT IN CMD:              //python is a script so no need to compile
    python $(NAME_PART).py
    GOTO EXITSCRIPT
    
    :EXITSCRIPT
    // that's all, folks!
    
    0 讨论(0)
  • 2020-11-30 01:12

    Decompile with CMD:

    If those didn't work try this:

    cmd /K g++ "$(FULL_CURRENT_PATH)" -o "$(FULL_CURRENT_PATH).exe
    

    It should save where you got the file (Example: If I got file from Desktop, it will be saved as .exe on the Desktop)

    I don't know if it works on 64 bits though so you can try it!

    0 讨论(0)
  • 2020-11-30 01:13

    You can actually compile and run C code even without the use of nppexec plugins. If you use MingW32 C compiler, use g++ for C++ language and gcc for C language.

    Paste this code into the notepad++ run section

    cmd /k cd $(CURRENT_DIRECTORY) && gcc $(FILE_NAME) -o $(NAME_PART).exe  && $(NAME_PART).exe && pause
    

    It will compile your C code into exe and run it immediately. It's like a build and run feature in CodeBlock. All these are done with some cmd knowledge.

    Explanation:

    1. cmd /k is used for testing.
      • Full explanation @ http://ss64.com/nt/cmd.html
    2. cd $(CURRENT_DIRECTORY)
      • change directory to where file is located
    3. && operators
      • to chain your commands in a single line
    4. gcc $(FILE_NAME)
      • use GCC to compile File with its file extension.
    5. -o $(NAME_PART).exe
      • this flag allow you to choose your output filename. $(NAME_PART) does not include file extension.
    6. $(NAME_PART).exe
      • this alone runs your program
    7. pause
      • this command is used to keep your console open after file has been executed.

    For more info on notepad++ commands, go to

    http://docs.notepad-plus-plus.org/index.php/External_Programs

    0 讨论(0)
  • 2020-11-30 01:18

    Here is the code for compling and running java source code: - Open Notepadd++ - Hit F6 - Paste this code

    npp_save <-- Saves the current document
    CD $(CURRENT_DIRECTORY) <-- Moves to the current directory
    javac "$(FILE_NAME)" <-- compiles your file named *.java
    java "$(NAME_PART)" <-- executes the program
    

    The Java Classpath variable has to be set for this...

    Another useful site: http://www.scribd.com/doc/52238931/Notepad-Tutorial-Compile-and-Run-Java-Program

    0 讨论(0)
提交回复
热议问题