• Login
Community
  • Login

Paste the output of an executable (exe) in Notepad++ current file

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 1.4k Views
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.
  • A
    Amit
    last edited by Amit Jun 16, 2022, 5:41 PM Jun 16, 2022, 5:40 PM

    I would like to “run” an external command (say dir with a directory path) and return the output pasted in current file opened in Notepad++.

    I have tried to use RUN command as follows: It does copy the output in the windows clipboard. But I prefer to be pasted in current location.

    cmd /c "dir $(CURRENT_DIRECTORY) | clip"
    

    Can you guys please help? Is there a better way to do this? I prefer not to use any extension or plugin for this.

    Thank you.

    A P 2 Replies Last reply Jun 16, 2022, 5:56 PM Reply Quote 0
    • A
      Alan Kilborn @Amit
      last edited by Jun 16, 2022, 5:56 PM

      @amit

      Sorry, there’s no integrated “run something, collect its output, then paste at current caret location” kind of command.

      1 Reply Last reply Reply Quote 0
      • P
        PeterJones @Amit
        last edited by Jun 16, 2022, 6:58 PM

        @amit ,

        As @Alan-Kilborn said, there is no builtin that does that, and unfortunately the saved RUN menu actions are not macro-recordable. But if you are willing to install a plugin, then a scripting plugin (like PythonScript) could do it with a few commands.

        A couple options using PythonScript.

        • Option 1:
          • Save your RUN command under the name DirectoryToClipboard,
          • Follow the instructions linked at the end to create the following script:
            from Npp import editor,notepad
            notepad.runMenuCommand("Run", "DirectoryToClipboard")`
            editor.paste()
            
        • Option 2:
          • Don’t bother saving the run command
          • Create a script similar to the above, with normal Python 2.7 commands to either capture the output of your cmd.exe /c dir or use Python libraries to directly grab the directory contents and create a string. Once you have the string, use editor.addText(txt) to type it into the active editor (no faffing about with the clipboard needed).
            from Npp import editor, notepad
            ... # your generic python to get the string into variable "txt" goes here
            editor.addText(txt)
            
            • As this isn’t a general purpose Python board, this isn’t the right place to delve into the details of the “generic python” option, since it has no Notepad++ specifics. But some hints: 1) maybe search the internet for python 2.7 capture output of system command to string, or 2) maybe search for python 2.7 get list of directory entries and python 2.7 convert list to string

        ----
        For more info on how to save and run the example script, see the FAQ: Install and run a script in PythonScript; this includes info on how to assign a keyboard shortcut to the script

        A 1 Reply Last reply Jun 16, 2022, 9:04 PM Reply Quote 0
        • A
          Amit @PeterJones
          last edited by Jun 16, 2022, 9:04 PM

          @peterjones I will give pythonscript plugin a try. Thank you. Really appreciate a detailed answer.

          1 Reply Last reply Reply Quote 0
          2 out of 4
          • First post
            2/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors