Rambo.run

You're seeing just the function run, go back to Rambo module for more information.

Specs

run(command :: String.t() | result()) :: result()

Runs command.

Executes the command and returns {:ok, %Rambo{}} or {:error, reason}. reason is a string if the child process failed to start, or a %Rambo{} struct if the child process started successfully but exited with a non-zero status.

Multiple calls can be chained together with the |> pipe operator to simulate Unix pipes.

Rambo.run("ls") |> Rambo.run("sort") |> Rambo.run("head")

If any command did not exit with 0, the rest will not be executed and the last executed result is returned in an :error tuple.

See run/2 or run/3 to pass arguments or options.

Examples

iex> Rambo.run("echo")
{:ok, %Rambo{out: "\n", status: 0, err: ""}}
Link to this function

run(command, args_or_opts)

View Source

Specs

run(command :: String.t() | result(), args_or_opts :: args() | Keyword.t()) ::
  result()

Runs command with arguments or options.

Arguments can be a string or list of strings. See run/3 for options.

Examples

iex> Rambo.run("echo", "john")
{:ok, %Rambo{out: "john\n", status: 0}}

iex> Rambo.run("echo", ["-n", "john"])
{:ok, %Rambo{out: "john", status: 0}}

iex> Rambo.run("cat", in: "john")
{:ok, %Rambo{out: "john", status: 0}}
Link to this function

run(command, args, opts)

View Source

Specs

run(command :: String.t() | result(), args :: args(), opts :: Keyword.t()) ::
  result()

Runs command with arguments and options.

Options

  • :in - pipe iodata as standard input
  • :cd - the directory to run the command in
  • :env - map or list of tuples containing environment key-value as strings
  • :log - stream standard output or standard error to console or a function. May be :stdout, :stderr, true for both, false for neither, or a function with one arity. If a function is given, it will be passed {:stdout, output} or {:stderr, error} tuples. Defaults to :stderr.
  • :timeout - kills command after timeout in milliseconds. Defaults to no timeout.

Examples

iex> Rambo.run("/bin/sh", ["-c", "echo $JOHN"], env: %{"JOHN" => "rambo"})
{:ok, %Rambo{out: "rambo\n", status: 0}}

iex> Rambo.run("echo", "rambo", log: &IO.inspect/1)
{:ok, %Rambo{out: "rambo\n", status: 0}}