Socket.Port (socket2 v2.1.1)

This module wraps local running program using Port.

Options

When creating a socket you can pass a series of options to use for it.

  • :as sets the kind of value returned by recv, either :binary or :list, the default is :binary
  • :packet see inet:setopts
  • :size sets the max length of the packet body, see inet:setopts
  • :env provides a map of environment variables for the subprocess

Examples

client = Socket.Port.open!("cat", packet: :line)

client |> Socket.Stream.send!("hi!

")

client |> Socket.Stream.recv!()
client |> Socket.Stream.close()

Summary

Functions

Convert Port options to :erlang.open_port compatible arguments.

Return a proper error string for the given code or nil if it can't be converted.

Create a Port based on the given command.

Create a Port based on the given command, raising if an error occurs.

Create a Port based on the given command and options, raising if an error occurs.

Types

@opaque t()

Functions

Link to this function

arguments(options)

@spec arguments(Keyword.t()) :: list()

Convert Port options to :erlang.open_port compatible arguments.

@spec error(term()) :: String.t()

Return a proper error string for the given code or nil if it can't be converted.

@spec open(binary() | list()) :: {:ok, t()} | {:error, Socket.Error.t()}

Create a Port based on the given command.

Link to this function

open(cmd, options)

@spec open(binary() | list(), Keyword.t()) :: {:ok, t()} | {:error, Socket.Error.t()}
@spec open!(binary() | list()) :: t() | no_return()

Create a Port based on the given command, raising if an error occurs.

Link to this function

open!(cmd, options)

@spec open!(binary() | list(), Keyword.t()) :: t() | no_return()

Create a Port based on the given command and options, raising if an error occurs.