4.5. Console output redirection

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:

- no output may be shown until child process ends (if this child process performs a lot of operations without explicit flushing of its output);

- 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);

- stdout and stderr output may be mixed (stdout and stderr are redirected into the same pipe);

- no output or incorrect output may happen when child process requires "real" console screen buffer.

The advantages:

+ NppExec's Console supports ANSI (Windows), OEM (DOS) and UTF-8 output and input (the standard console usually supports just OEM or ANSI);

+ NppExec's Console allows to change the console output using NppExec's Exclude/Include and Replacing filters;

+ NppExec's Console allows to highlight warnings/errors and process them using NppExec's Highlight filters.

If you want your console program's output to be redirected into a text file, you can use something similar to the following:

cmd /c program.exe >C:\temp\out.txt

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).

Then you can open this text file in Notepad++:

NPP_OPEN C:\temp\out.txt

Thus, you can use the following NppExec's script:

SET local OUTFILE = C:\temp\out.txt
cmd /c program.exe >$(OUTFILE)
NPP_OPEN $(OUTFILE)

See also: NppExec's Console [3.5]; NppExec's Console behaviour [4.1]; Using cmd.exe [4.4].