Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been using the NppExec console in Notepad to run python and ruby scripts using python script_name.py or ruby script_name.rb, and for the most part this works well: the output gets redirected into the NppExec console, and I don't have to switch out of Notepad++ to test my script.

However, what I would really like to be able to do is to run an interactive session of python or ruby from the NppExec console. For example, just python or just irb don't allow interactively working in the console.

Anyone had any luck with this?

If this were possible, it would mean being able to exercise functions / methods in a given script from within the console all without having to leave Notepad++.

share|improve this question
    
You can use pry (for Ruby) and add the lines require 'pry' and binding.pry to your code to open up the interactive console in the current scope. –  itdoesntwork Aug 20 '12 at 2:42
    
@itdoesntwork: seems wrong to say it, but... it doesn't work! Seriously though, are you sure you have got this to work calling pry from within the console window in Notepad++ (NppExec)? Appreciate the tip on pry -- have just installed the gem, and it does seem better than irb. But I don't think it gets me what I'm hoping for: running ruby interactively from within Notepad++ itself. Let me know if I'm missing something. –  Assad Ebrahim Aug 20 '12 at 3:05

3 Answers 3

This doesn't look like it's possible. From the NppExec documentation, I quote:

NppExec is NOT...

  • NppExec is not a console emulator. NppExec redirects the running process'es output to its Console window, and can redirect the Console window's input to the running process (with some limitations). The NppExec's Console is not a "real" console window (actually, it uses RichEdit control for text input/output), it does not provide a console screen buffer. Thus, a console application which requires a "real" console screen buffer must be run in its own console window (using NPP_RUN command).

  • NppExec is not a command interpreter. NppExec does not understand such commands as 'copy', 'call', 'for' and so on because it is neither a "real" console nor a console emulator. However, NppExec has its own internal implementation of such commands as 'cls', 'cd', 'dir', 'echo', 'set' ('env_set') and introduces other, specific, commands. Also you can use "cmd /c " to execute any cmd's command inside NppExec.

  • NppExec is not a compiler. NppExec allows you to use external tools and compilers to process/compile your current file, but it has no ability to do it by itself. No magic here :)

Since there is no console screen buffer, the NppExec console cannot qualify as a "real" console.

You're much better off trying an application that was designed for interactive testing of code, such as IPython for Python.

share|improve this answer
    
Thanks for the response. Your quote about console buffers, NppExec and Npp_run got me looking into this again and testing what exactly NppExec's console buffers do with respect to i/o. Apparently, they do take both input and reflect output. So the simple python program print("Enter anything: ", end=""); response=input(); print(response) will work when called from within Npp_Exec's console using python $(FILE_NAME). This has led me to a solution that works -- see answer. So (+1) for partial response that motivated finding an actual solution! Thanks. –  Assad Ebrahim Sep 6 '12 at 18:11
up vote 0 down vote accepted

Edit (Adding -u unbuffered switch for better performance)

Turns out this is possible for Python using the -i (inspect) switch and the -u (unbuffered output) switch, despite the fact that Npp_Exec is not a true console:

    python -u -i $(FULL_CURRENT_PATH)

This runs the current file in the Npp_Exec console in the Python interpreter and because of -i switch jumps straight into interactive mode where you can then continue from within the NppExec console to inspect / use any variables or definitions provided by the script.

If you set your Npp_Exec console to follow the current directory using Notepad++ Menu > Plugins > NppExec > Follow $(CURRENT_DIRECTORY, the solution is even simpler:

    python -u -i $(FILE_NAME)

(Note: For Ruby this is still an open question, since Ruby and its interactive interpreter irb are two separate binaries, and don't seem to have an inspect type switch along with some other oddities when running scripts that have both input and output... )

share|improve this answer

I'm new to python and tried to learn python programming and because of some issues in IDLE(like line-numbering) I decided to use Notepad++ and of course NPP_EXEC plugin to ease code compiling. I had succeeded in some others like compiling *.vbs files but this time for python it was not triumph for some reason despite all the solution presented here and else where.

I tried first the python -u "$(FULL_CURRENT_PATH)" in NPP_EXEC. For some python scripts the result was satisfactory and as I proceeded in learning more in python I encountered a problem again because the output was not as I expected. I ran into the solution here by [AKE]. unfortunately none of these worked out to me up to now.

suppose the following code.

#-------------------------------------------------
my_dict = dict({'Alice':1, 'John':2, 'Emma':3})
name = raw_input("enter the name: ")
name = name.capitalize()

if name in my_dict:
    #do something here
else: print("The name does not exist!")
#-------------------------------------------------

I used both:

python -u "$(FULL_CURRENT_PATH)"
and
python -u -i "$(FULL_CURRENT_PATH)"

but the result's always the same, whatever you enter as name in the above code the output is always:
[The name does not exist!]

I believe it's because of the -u switch, so I tried to omit it and use just -i as

python -i "$(FULL_CURRENT_PATH)"

It turned out to work but this time after you observed the output you have to press Ctrl+C to terminate the process manually and exit python interactive mode in NPP_EXEC console.

I know of some other work-arounds like using Notepad++ Run menu and adding some commands there or even using PyNPP plugin (although these two do almost identical procedure by redirecting python on cmd), but none of these had the convenience as I liked. Maybe I Expect too much of NPP_EXEC, because as it has in its help it's not a real console, but I wanted to do it all in Notepad++ without dealing with some other processes like IDLE or cmd or ....

Despite this I would appreciate any help if someone had any other successful experience.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.