<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Is it possible to run text through an external program?]]></title><description><![CDATA[<p dir="auto">I guess this is a bit of how TextFX works and I suppose I’m asking “can I write my own TextFX-like filters” and have n++ send the selected text through the program and replace the text with its output</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/16158/is-it-possible-to-run-text-through-an-external-program</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 21:32:56 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/16158.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 11 Aug 2018 15:18:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is it possible to run text through an external program? on Sun, 12 Aug 2018 23:12:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> Perfect… thanks very much!!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34113</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34113</guid><dc:creator><![CDATA[bcosell]]></dc:creator><pubDate>Sun, 12 Aug 2018 23:12:45 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to run text through an external program? on Sat, 11 Aug 2018 22:58:00 GMT]]></title><description><![CDATA[<p dir="auto">The literal answer to your question is “yes.”  I am assuming, however, that you’d also like to know how. :-)</p>
<p dir="auto">Using the NppExec plugin, you can grab the selected text and pass it through another program, and then grab the results.  Here is one where I had NppExec grab the entire contents of the given window, save it to a temporary file, pass it through gpg to decrypt it, and paste the contents back into that same NPP window.</p>
<pre><code>cls
npp_save
cmd.exe /c exit %RANDOM%														// cannot access $(SYS.RANDOM) directly through NppExec, but can tell cmd.exe to return it as a value
set tempfile = $(SYS.TEMP)\NppGpgFile_$(EXITCODE).tmp							// create random tempfile name
set ascfile = $(SYS.TEMP)\NppGpgFile_$(EXITCODE).asc							// create associated ascfile name
sci_sendmsg SCI_SELECTALL														// select all
sel_saveto $(ascfile) :a														// save selection to the ascfile	(use :a to save as ansi, to prevent unicode prefix ÿþ getting embedded)
gpg.exe --output "$(tempfile)" --decrypt "$(ascfile)"							// decrypt
sel_loadfrom $(tempfile)														// replace selection with results
sci_sendmsg SCI_DOCUMENTSTART													// deselect
rm -rf "$(tempfile)" "$(ascfile)"												// cleanup temp files
npp_save
</code></pre>
<p dir="auto">Since you want to make use of what you’ve already selected, you wouldn’t need (for eample) the <code>sci_sendmsg SCI_SELECTALL</code>, because you would want to leave the selection alone.  So, based on your description that it’s already selected, here’s something that should give you a starting place:</p>
<pre><code>cmd.exe /c exit %RANDOM%														// cannot access $(SYS.RANDOM) directly through NppExec, but can tell cmd.exe to return it as a value
set destfile = $(SYS.TEMP)\NppFilterDestinatino_$(EXITCODE).tmp					// create random destfile name
set sourcefile = $(SYS.TEMP)\NppFilterSource_$(EXITCODE).tmp					// create associated sourcefile name
sel_saveto "$(sourcefile)" :a													// save selection to the sourcefile	(use :a to save as ansi, to prevent unicode prefix ÿþ getting embedded)
c:\path\to\program.exe --output "$(destfile)" --source "$(sourcefile)"			// this is the program you're filtering it through; this will work if your program can take input and output filenames at the command prompt
// however, if your program only uses STDIN and STDOUT, then do something like:
// type "$(sourcefile)" | c:\path\to\program.exe &gt; "$(destfile)"				// this uses windows pipes and redirection so your program.exe takes STDIN and outputs to STDOUT, but NppExec can interface with the files
sel_loadfrom "$(destfile)"														// replace selection with results
rm -rf "$(destfile)" "$(sourcefile)"											// cleanup temp files
</code></pre>
<p dir="auto">I left in the random file naming for the tempfiles, because it should keep collisions from occurring.  I included options for either command-line arguments to your program.exe, or using windows <code>type</code>, along with an input pipe and output redirection, so that your program could use STDIN-&gt;STDOUT.</p>
<p dir="auto">NppExec comes with pretty thorough documentation, but if you have any questions about this outline, feel free to ask.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34098</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34098</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Sat, 11 Aug 2018 22:58:00 GMT</pubDate></item></channel></rss>