View Source ExCmd.Process (ex_cmd v0.7.0)

Server to interact with external process

ExCmd.stream! should be preferred over this. Use this only if you need more control over the life-cycle of IO streams and OS process.

Link to this section Summary

Functions

Waits for the program to terminate.

Returns a specification to start this module under a supervisor.

Closes input stream. Which signal EOF to the program

Returns os pid of the command

Return bytes written by the program to output stream.

Starts a process using cmd_with_args and with options opts

Returns status of the process. It will be either of :started, {:done, exit_status}

Kills the program

Writes iodata data to programs input streams

Link to this section Functions

Link to this function

await_exit(server, timeout \\ :infinity)

View Source

Specs

await_exit(pid(), [{:timeout, timeout()}]) :: {:ok, integer()} | :timeout

Waits for the program to terminate.

If the program terminates before timeout, it returns {:ok, exit_status} else returns :timeout

Returns a specification to start this module under a supervisor.

See Supervisor in Elixir v1.6+.

Specs

close_stdin(pid()) :: :ok | {:error, any()}

Closes input stream. Which signal EOF to the program

Specs

os_pid(pid()) :: integer()

Returns os pid of the command

Returns port_info

Link to this function

read(server, timeout \\ :infinity)

View Source

Specs

read(pid(), non_neg_integer() | :infinity) ::
  {:ok, iodata()} | :eof | {:error, String.t()} | :closed

Return bytes written by the program to output stream.

This blocks until the programs write and flush the output

Link to this function

start_link(list, opts \\ [])

View Source

Specs

start_link([String.t(), ...],
  cd: String.t(),
  env: [{String.t(), String.t()}],
  log: boolean()
) :: {:ok, pid()} | {:error, any()}

Starts a process using cmd_with_args and with options opts

cmd_with_args must be a list containing command with arguments. example: ["cat", "file.txt"].

options

Options

  • cd - the directory to run the command in
  • env - a list of tuples containing environment key-value. These can be accessed in the external program
  • log - When set to true odu logs and command stderr output are logged. Defaults to false

Specs

status(pid()) :: :started | {:done, integer()}

Returns status of the process. It will be either of :started, {:done, exit_status}

Kills the program

Link to this function

write(server, data, timeout \\ :infinity)

View Source

Specs

write(pid(), iodata(), non_neg_integer() | :infinity) ::
  :ok | {:error, String.t()} | :closed

Writes iodata data to programs input streams

This blocks when the pipe is full