Paste the output of an executable (exe) in Notepad++ current file
-
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.
-
Sorry, there’s no integrated “run something, collect its output, then paste at current caret location” kind of command.
-
@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()
- Save your RUN command under the name
- 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 diror use Python libraries to directly grab the directory contents and create a string. Once you have the string, useeditor.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 forpython 2.7 get list of directory entriesandpython 2.7 convert list to string
- 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
-—
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 - Option 1:
-
@peterjones I will give pythonscript plugin a try. Thank you. Really appreciate a detailed answer.
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