jump to navigation

Launch your program from within Notepad++ February 22, 2009

Posted by razasayed in programming.
Tags: , ,
trackback

Notepad++ is a good editor for programmers, that supports multiple languages, and also has some other cool features like syntax highlighting, some basic intellisense etc.. . It is free and open source , but the downside is that its available only for Windows . However, it does work on Linux too, by using Wine. Notepad++ is a good alternative for people (especially those using Windows,on Linux  vi or  emacs  are the commonly used editors) who for whatever reason are not using full fledged IDE’s , and want a simple editor with some of the bells and whistles required for their programming work.

Recently, i discovered a cool feature supported by Notepad++, which i thought id blog about . How many times have we encountered situations where we write code in an editor and then switch back to the command line to execute it , especially if we are dealing with interpreted languages like perl, python , ruby etc..

Wouldnt it be nice if we could execute the program within the editor itself  ?. Now that would come in really handy . Would definitely save us some time and overhead involved in the context switch 😉 .

Guess what, Notepad++ being plugin based , has a plugin called NppExec , which allows us to do just that .  All you have to do is download it (assuming this plugin is not already installed)  , then after extracting the archive, place the dll in <Notepad++ Installation directory>/plugins .

Heres how to use it (assuming you are using python , and have the python interpreter installed on your system , however it could be any other language for which you have the corresponding interpreter installed)

Step 1) First type in your program and save the file

Step 2) Go to Plugins->NppExec->Execute (or press F6), and in command section type


python "$(FULL_CURRENT_PATH)"

$(FULL_CURRENT_PATH) , is a Notepad++ internal variable ,that contains the full path of the file currently open in the editor . There is a list of 10 such global variables here

Step 3) Now click on Save, and type a name for this script, so that we can use it again later on.

Step 4) Press OK

Voila, you can now see the output of your program in a console window in the editor itself ! .

Then again when you make some changes to your code, you dont have to go through all the above steps again, simply press Ctrl+F6, which is the shortcut for repeating the previous command.  To switch to a different language you can press F6 and select any other language for which you have saved a script.

Tip : If you dont want those extra messages that you see along with the output, just select Plugins->NppExec->No Internal Messages

Hope someone finds this useful,

Have fun 🙂

Advertisements

Comments»

1. Björn - March 28, 2009

Thanks Raza
I was previously only aware of plain Run, which is less useful for executing python scripts.

2. Maks - April 21, 2009

thank you very much!

3. kaustubh - June 18, 2009

Yeah, I loved it. Thanks i was really finding some flick ALL ROUND IDE, i been fan of TexMate, Wish i could have something similar, I gonna give it a try.

One SEO TIP TO YOU RAZA go to your wordpress client backbone and in setting->permalinks put this value /%postname%/ in custom structure, that will remove the date segment from url and would hopefully give more weightage to your content which will be bringing you some good organic traffic.

4. Björn - June 18, 2010

NppExec and Python doesn’t seem to be a popular discussion topic, I just found this old post again!
I would like to point out the following useful feature:

In Plugins – NppExec – Console Output filters (shift-F6)
add the following *HighLight* mask:

*File “%ABSFILE%”, line %LINE%, in*

Make sure it’s checked, and make it e.g. red and underlined.

Upon “F6/execute” errors will be highlighted and clickable !

This works in NPP568, possibly older.
With this I may actually be able to use NPP instead of Idle.

5. Cấu hình notepad++ để chạy compiler, interpreter…. và hiển thị thông bá o « tucm - October 4, 2011

[…] https://razasayed.wordpress.com/2009/02/22/launch-your-program-from-within-notepad/ Like this:LikeBe the first to like this post. […]

6. prrao - February 15, 2012

Hi, I know this might be kind of late, but I agree with Bjorn. I can’t believe that NppExec doesn’t appear on more online posts for running Python scripts.
I had a small issue. In case my Python script has a bug (say an infinite loop for example) and I want to kill my Python process, how do I do it with NppExec? Right now, I get the ‘Process started >>>’ message and I want to kill it so I can debug and rerun. The only option seems to be to close Notepad++ and reopen. is there a better way?

Holoovooloo - March 28, 2012

At least on windows you can terminate the process with CTRL+C

7. Anonymous - May 7, 2012

VM Thanks, exactly what I needed to run REXX scripts

8. Yurij newbie - May 30, 2012

is it possible to pass selected text to browser (chrome) from npp?
howto pass not path to TEMP_FILE but content?
—need a correction—
set ChromeRun = C:\Documents and Settings\My\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
set TEMP_FILE = $(SYS.TEMP)\npp_sel.txt
// save current selection as ANSI text file
SEL_SAVETO $(TEMP_FILE) :a
// run Chrome.exe for this file
$(ChromeRun) –homepage $(TEMP_FILE)

9. luke - June 21, 2012

Thank you Sir! It works very well, very good instructions! Thanks again!

10. Jocke - October 21, 2012

Thanks, that turned out to be a very useful hint!

11. Raihan Tusher - March 20, 2014

You can run java program in your notepad++
download the plugin from here

12. Lakshmanan M - October 1, 2014

I get the following in the console

ruby C:\Users\admin\Desktop\wecom.rb
CreateProcess() failed with error code 2:
The system cannot find the file specified.

================ READY ================

13. Prevalidator (@prevalidator) - July 14, 2015

If I execute (run) a program from ++ it opens a cmd prompt window, runs the program and disappears. How can I keep the window open?
Thanks

Lakshmanan M - July 15, 2015

Try running the program as adminsitrator.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: