If you plan to use an external process (which you indicated in a comment on another question), you can use the following:
(start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)
This will return the process object. You can either send the output to the buffer, or you can attach a filter function to a process. In the latter case, it is a function that is called every time your process emits any output.
In addition, you can attach a watch function to your process. This function is called every time the state of your process changes, it is useful to find out when it exited.
Emacs source code provides several examples, one of which is compile.el
.
Lindydancer
source share