<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML lang="en">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<link href="style.css" rel="stylesheet" type="text/css">
<title>4.5. Console output redirection</title>
<script src="show_matches.js" type="text/javascript"></script>
</HEAD>
<BODY>
<h3>4.5. Console output redirection</h3>
<p>By default, when you run some console program using NppExec, the program's output is shown in NppExec's Console. It is possible because the console program is started as a child process of NppExec. NppExec uses pipes to redirect child process'es output to NppExec's Console window and to redirect user's input from NppExec's Console window to child process'es input. Such approach has several known limitations:</p>
<blockquote>
  <p>- no output may be shown until child process ends (if this child process performs a lot of operations without explicit flushing of its output); </p>
  <p>- no output may be shown while child process waits for initial input (this may happen with some interpreters, but does not happen with cmd.exe);</p>
  <p>- stdout and stderr output may be mixed (stdout and stderr are redirected into the same pipe);</p>
  <p>- no
        output or incorrect output may happen when child process requires &quot;real&quot; console
        screen buffer.</p>
</blockquote>
<p>The advantages:</p>
<blockquote>
  <p>+ NppExec's Console supports ANSI (Windows), OEM (DOS) and UTF-8 output and input (the standard console usually supports just OEM or ANSI);</p>
  <p>+ NppExec's Console allows to change the console output using NppExec's Exclude/Include and Replacing filters;</p>
  <p>+ NppExec's Console allows to highlight warnings/errors and process them using NppExec's Highlight filters.</p>
</blockquote>
<p>If you want your console program's output to be redirected into a text file, you can use something similar to the following:</p>
<blockquote>
  <pre>cmd /c program.exe &gt;C:\temp\out.txt</pre>
</blockquote>
<p>This will redirect the output of 'program.exe' into a text file 'out.txt' inside 'temp' folder on your drive C (this folder must exist).</p>
<p>Then you can open this text file in Notepad++:</p>
<blockquote>
  <pre>NPP_OPEN C:\temp\out.txt</pre>
</blockquote>
<p>Thus, you can use the following NppExec's script:</p>
<blockquote>
  <pre>SET local OUTFILE = C:\temp\out.txt
cmd /c program.exe &gt;$(OUTFILE)
NPP_OPEN $(OUTFILE)</pre>
</blockquote>
<p>See also: NppExec's Console <a href="3.5.html">[3.5]</a>; NppExec's Console behaviour <a href="4.1.html">[4.1]</a>; Using cmd.exe <a href="4.4.html">[4.4]</a>.</p>
</BODY>
</HTML>
