Is there any way to execute a command from notepad++
and have the results piped back into the program in a new tab?
3 Answers
If your program outputs plain text and you can run batch files...
Create a batch file (e.g. dir.bat) which pipes the results of your command to a temporary file, then opens the file in Notepad++ e.g.
dir > tmp "C:\path_to_notepad_plus_plus\notepad++" tmp
(replace dir with your command and add an extension to tmp to syntax-highlight it appropriately).
In Notepad++, select Run > Run... and browse for your batch file.
- If you use it often, consider saving it as a macro (Run > Run... > Save...) which you can access with a keyboard shortcut or under the Run menu.
-
Don't name the batch file
dir.bat
becausedir
is the name of built in command. Jan 6, 2022 at 16:18
For more flexible, you can install the NppExec plugin. The easiest way to install it is through the built-in Plugin Manager:
- Select Plugins / Plugin Manager / Show Plugin Manager
- Put a checkmark next to NppExec
- Click Install
After that, the fun begins. This tutorial is a good starting point on how to use this powerful plugin: https://micksmix.wordpress.com/2009/09/24/format-your-perl-scripts-using-perltidy-and-notepad/
It should work with any command-line utility that outputs text to the console.
-
Sorry, but it did not answer the OP's question of how to do it. Jun 16, 2022 at 17:30
Another option if you cannot install plugins and can only use Notepad++'s Run command is to utilize piping the output to the Windows clipboard which allows you to paste the output wherever you want.
As an example I use the following to checkout perforce files using the command line tool:
cmd /c "cd /d $(CURRENT_DIRECTORY) & C:\Progra~1\Perforce\p4.exe edit $(FULL_CURRENT_PATH) | clip"
The base of this is cmd /c "your_commands | clip"
which runs a command, terminates the program when done and sends all the output to the Windows clipboard via the command clip
.
After the command runs you can paste the contents of your clipboard somewhere (such as a new file) if you need or want the output.
-
Good tip, but I think you should explain that
clip
is a command included with Windows. Jan 6, 2022 at 16:45