Go to the first, previous, next, last section, table of contents.


Receiving Output from Processes

There are two ways to receive the output that a subprocess writes to its standard output stream. The output can be inserted in a buffer, which is called the associated buffer of the process, or a function called the filter function can be called to act on the output. If the process has no buffer and no filter function, its output is discarded.

Output from a subprocess can arrive only while Emacs is waiting: when reading terminal input, in sit-for and sleep-for (see section Waiting for Elapsed Time or Input), and in accept-process-output (see section Accepting Output from Processes). This minimizes the problem of timing errors that usually plague parallel programming. For example, you can safely create a process and only then specify its buffer or filter function; no output can arrive before you finish, if the code in between does not call any primitive that waits.

Subprocess output is normally decoded using a coding system before the buffer or filter function receives it, much like text read from a file. You can use set-process-coding-system to specify which coding system to use (see section Process Information). Otherwise, the coding system comes from coding-system-for-read, if that is non-nil; or else from the defaulting mechanism (see section Default Coding Systems).

Warning: Coding systems such as undecided which determine the coding system from the data do not work entirely reliably with asynchronous subprocess output. This is because Emacs has to process asynchronous subprocess output in batches, as it arrives. Emacs must try to detect the proper coding system from one batch at a time, and this does not always work. Therefore, if at all possible, use a coding system which determines both the character code conversion and the end of line conversion--that is, one like latin-1-unix, rather than undecided or latin-1.


Go to the first, previous, next, last section, table of contents.