Executing Java/Python in Notepad++ Portable
I recently figured out how to install Java in such a way on my flashdrive that it is easy for me to execute Java from Portable Notepad++ using the following tutorial: http://www.quarkphysics.ca/scripsi/java_notepad/
However, after this, I have two questions. My programming teacher at my high school was curious as to whether or not I could get out of the standard Notepad++ output and get the code to output in a Win32 Console (examples of this type of GUI being powershell or command prompt). It’s something that Textpad does when I execute Java and I was curious if I could have that on Notepad++ as well as it’s my preferred source code editor.
Also! I was curious if anyone could help me set this up to do the same thing in Python??? Thanks!
Why do you want it in a separate window? NPP_EXEC’s in-Notepad++ console has the ability to copy/paste results.
If you want to have access to the cmd.exe interpreter after running your command, but are willing to have it in the NPP_EXEC console window inside Notepad++, you can change the “Java-run” from
cd "$(CURRENT_DIRECTORY)" "\java\jdk1.7.0_11\bin\java" -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
cd "$(CURRENT_DIRECTORY)" cmd /k "\java\jdk1.7.0_11\bin\java" -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
(and similarly for the other scripts from the example page you showed).
But if you insist on a separate window, prefix it with
npp_run cmd /kinstead of
cmd /kto spawn it in a separate window instead of the NPP_EXEC console, like
cd "$(CURRENT_DIRECTORY)" npp_run cmd /k "\java\jdk1.7.0_11\bin\java" -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
Note that every instance of
npp_run cmd /kwill get its own command window.
To emphasize, there isn’t much benefit to running it in a separate window, except if you like extra windows cluttering your taskbar. If you are insistent upon spawning a new window, be selective about which scripts you add it to. I see no reason for the Java-Compile or Java-Applet-HTML/Java-Applet-Run scripts to spawn a new window (compile is non-interactive, and the HTML-applet just creates an HTML file that is run in a separate process anyway). You might make a mild case for Java-Run to be a separate window, but you’d have to give a strong argument to convince me.
Running an external Python script could be done similarly to the Java-Run script, except you would use the path to your python.exe instead of your java.exe – and similarly, if you want the python output in a separte window, you could use
npp_run cmd /kto prefix.
// in the `Console` window, without a cd: "c:\python27\python.exe" "$(FULL_CURRENT_PATH)" // in the `Console` window, with a cd, so that later you can run the command again without using your script cd "$(CURRENT_DIRECTORY)" "c:\python27\python.exe" "$(NAME_PART)" // edit your script, save, then type the following to run it again without clearning the console window: "c:\python27\python.exe" "$(NAME_PART)" // in the `Console` window, but allow `cmd.exe` commands to be run inside the window, from the same directory, after the script is run cd "$(CURRENT_DIRECTORY)" cmd /k "c:\python27\python.exe" "$(NAME_PART)" // in a separate window cd "$(CURRENT_DIRECTORY)" npp_run cmd /k "c:\python27\python.exe" "$(NAME_PART)"
Note, if you are a fan of Python, you might also consider the Python Script Plugin for Notepad++, which allows you to use a python script to automate things inside Notepad++ (as the next level of scripting beyond NPP_EXEC’s capabilities)
My teacher is more used to the cmd output and wanted it that way to review my programs, whereas I prefer the NppExec console and overall prefer Notepad++ as a source code editor. Thank you for your help!
Getting this error, though: https://ibb.co/mOVfxQ
Both versions of your code are doing this.
Not sure what the issue is, Java-Run is working fine: https://ibb.co/hs3dj5
it’s should be launching the right programs, based on those screenshots.
What drive is java installed on? Assuming it’s on
U:, it may be that with the
npp_run cmd /kprefix, you have to change to
npp_run cmd /k "c:\java\jdk1.7.0_11\bin\java" -classpath "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
to explicitly indicate which drive java is on.
Searching on your error text, it usually indicates a special character not properly quoted. Those don’t look like accidental smartquotes in your screenshot, but you might want to check for that. And what happens if you do the
cmd /kversion without the npp_run (try the intermediate step, to debug whether it’s cmd.exe or npp_run which is going from not-working to working)