Community
    • Login

    Executing Java/Python in Notepad++ Portable

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 2 Posters 5.8k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Someone AnonymousS Offline
      Someone Anonymous
      last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones
        last edited by

        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)"
        

        to

        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 /k instead of cmd /k to 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 /k will 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 /k to 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)

        1 Reply Last reply Reply Quote 2
        • Someone AnonymousS Offline
          Someone Anonymous
          last edited by

          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!

          1 Reply Last reply Reply Quote 0
          • Someone AnonymousS Offline
            Someone Anonymous
            last edited by Someone Anonymous

            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

            1 Reply Last reply Reply Quote 0
            • PeterJonesP Offline
              PeterJones
              last edited by

              it’s should be launching the right programs, based on those screenshots.

              What drive is java installed on? Assuming it’s on C:, not U:, it may be that with the cmd /k or npp_run cmd /k prefix, 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 /k version 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)

              1 Reply Last reply Reply Quote 0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors