Table 15.1: Port Creation BIF

    PortName is usually a tuple {spawn,Command}, where the string Command is the name of the external program. The external program runs outside the Erlang workspace, unless a port driver with the name Command is found. If Command is found, that driver is started.

    PortSettings is a list of settings (options) for the port. The list typically contains at least a tuple {packet,N}, which specifies that data sent between the port and the external program are preceded by an N-byte length indicator. Valid values for N are 1, 2, or 4. If binaries are to be used instead of lists of bytes, the option binary must be included.

    As of Erlang/OTP R16, messages sent to ports are delivered truly asynchronously. The underlying implementation previously delivered messages to ports synchronously. Message passing has however always been documented as an asynchronous operation. Hence, this is not to be an issue for an Erlang program communicating with ports, unless false assumptions about ports have been made.

    In the following tables of examples, Data must be an I/O list. An I/O list is a binary or a (possibly deep) list of binaries or integers in the range 0..255:

    Table 15.2: Messages Sent To a Port

    Instead of sending and receiving messages, there are also a number of BIFs that can be used:

    Table 15.4: Port BIFs

    Some additional BIFs that apply to port drivers: port_control/3 and erlang:port_call/3.