FAQ (Frequently Asked Questions)

Q1. Why program output is wrong in NppExec?

To answer this question, let's mention the most common problems one may face in NppExec's Console first:

Looking at this list, you are surely thinking: quite a few problems, man! Why have you introduced them?

Well, I can assure you: this is not something intended. This is a limitation of the technique that NppExec uses to capture program's output.

In short, NppExec does not use a real console (also known as "terminal"). Instead, NppExec uses pipes to "communicate" with an external program. And sometimes, depending on a program, these pipes do not work as expected. Technical details are explained in [4.8.3], from the point (6).

Fortunately, there are workarounds for these issues which are explained below, in Q3.

 

Q2. Why NppExec does not use real console (terminal)?

Very good question!

I'll try to give a good answer.

The main purpose of NppExec is its deep integration with Notepad++. NppExec achieves it by:

All of the above is not possible in a real console. Because there is no connection between a real console and Notepad++. A real console does not know anything about $(FILE_NAME); it can't save a file in Notepad++; it can not alter the text selected in Notepad++; it can not produce clickable warnings and errors allowing to go to the corresponding file and line in Notepad++. And so on. Different tools, different abilities.

So, NppExec provides some benefits with respect to integration with Notepad++, but lacks some benefits of the real console. Well, some sort of trade-off.

 

Q3. How can I get proper program output in NppExec?

The short answer is: run this program using the system's command-line interpreter which is cmd.exe. As NppExec lacks the features of the real console, the logical solution is to execute a program in a separate console window.

There are two ways to achieve this:

1. Using npp_run:

npp_run program.exe

This runs a program program.exe in a separate window (not in NppExec's Console). In this case, NppExec does not have any control over the program.exe - it does not know if the program is running or has it finished.

To run the program with arguments such as arg1 and arg 2, use:

npp_run program.exe arg1 "arg 2"

2. Using cmd /C start /wait:

cmd /C start /wait "some title" program.exe

In this case, cmd itself is running within NppExec's Console, so NppExec waits until the cmd is finished. In the same time, start /wait instructs the cmd to run the program.exe in a separate window and wait until the program.exe is finished.

Correspondingly, we have the program.exe running in its own window and NppExec's Console waiting for the program.exe to finish. This is the advantage of cmd /C start /wait over npp_run.

The "some title" is the title of the console window started by the cmd /C start /wait.

To run the program with arguments such as arg1 and arg 2, use:

cmd /C start /wait "some title" program.exe arg1 "arg 2"

Now, what if program.exe exits too fast - and, instead, we want its console output to remain until we read it? In such case, we are adding another explicit usage of cmd /C, this time calling it with pause:

cmd /C start /wait "some title" cmd /C "program.exe arg1 "arg 2" && pause"

Finally, let's consider a more complicated scenario. What if we want to compile a file currently opened in Notepad++ and then to run the produced executable with some arguments? To do that, the following commands can be used:

npp_save  // save the current file
cd $(CURRENT_DIRECTORY)  // cd to the directory of the current file
npe_console local -- x+  // enable the built-in error highlight filter
compiler.exe "$(FILE_NAME)"  // compile the current file in NppExec's Console
if $(EXITCODE) != 0 then  // check the compiler's exit code
  exit  // the compiler did not succeed, no sense to continue
endif
cmd /C start /wait "$(NAME_PART)" "$(NAME_PART).exe" arg1 "arg 2"  // run the compiled file
npp_setfocus con  // return the focus back to NppExec's Console

The sequence of the commands above is called NppExec's script [3.7].

To run the compiled file (executable) and preserve its console output, use the same technique with cmd /C and pause as shown above:

cmd /C start /wait "$(NAME_PART)" cmd /C ""$(NAME_PART).exe" arg1 "arg 2" && pause"

 

Q4. Why output redirection and command chaining do not work in NppExec?

They actually work by means of the system's command-line interpreter which is cmd.exe.

For example:

cmd /C program.exe >program.txt

and also:

cmd /C start /wait "example" cmd /C "echo Hello world! && pause"

See more examples in [4.4].

 

Q5. How can I compile my source code in NppExec?

In short, you need two things: a proper compiler for your programming language and a proper way of using this compiler by means of NppExec.

In general, each programming language and each compiler requires its own approach. The Q3 above briefly mentions a template of NppExec's script [3.7] that compiles the current file and runs the produced executable.

Please refer to other sections of the NppExec Manual to get an idea of how to compile the source code for the programming language you are interested in. In particular: