Bow.Exec (Bow v0.4.1) View Source

Transform files with shell commands

This module allows executing any external command taking care of temporary path generation and error handling. It is as reliable as erlexec module (very!).

It is also possible to provide custom command timeout. See exec/4 to see all available options.

Link to this section Summary

Link to this section Types

Specs

command() :: [String.t() | {:input, integer()} | :input | :output]

Link to this section Functions

Link to this function

exec(source, target, command, opts \\ [])

View Source

Specs

exec(Bow.t(), Bow.t(), command(), keyword()) :: {:ok, Bow.t()} | {:error, any()}

Execute command

Arguments:

  • source - source file to be transformed
  • target_name - target file
  • command - the command to be executed. Placeholders ${input} and ${output} will be replaced with source and target paths

Options:

  • :timeout - time in which the command must return. If it's exceeded the command process will be killed.

Examples

# generate image thumbnail from first page of pdf
def transform(file, :pdf_thumbnail) do
  Bow.Exec.exec file, filename(file, :pdf_thumbnail),
    "convert '${input}[0]' -strip -gravity North -background '#ffffff'" <>
                      " -resize 250x175^ -extent 250x175 -format png png:${output}"
end