magic v0.3.2 Magic

The Magic module provides convenience sigil wrapper for Port cmd

Link to this section Summary

Functions

The macros catch all error and exception,

Async Run cmd

执行命令,如果命令不存或者命令执行失败 不会抛错 而是返回 {:error,reason}

执行命令,如果命令不存在则会报错,或者命令执行失败

Link to this section Functions

Link to this macro defp_protected(head, body) (macro)

The macros catch all error and exception,

transform them to normal output

Note: There are some critial performance issue

Examples:

import Magic
defp_protected oops! do
 raise ArgumentError, "oops!"
end

oops!() == {:error, %ArgumentError{message: "oops!"}}
Link to this function sigil_b(string, list)

Async Run cmd

Link to this function sigil_q(term, modifiers)

执行命令,如果命令不存或者命令执行失败 不会抛错 而是返回 {:error,reason}

Examples:

iex> import Magic
iex> ~q(echo 123)
{:ok, ["123"]}
Link to this function sigil_x(string, mod \\ [])

执行命令,如果命令不存在则会报错,或者命令执行失败

Examples:

iex> import Magic
iex> ~x(echo 123)
{:ok, ["123"]}

iex> import Magic
iex> ~x(./lib ls)c
{:ok, ["app.ex", "magic.ex", "random.ex", "shotgun.ex"]}

c = CD, 在指定路径执行命令