z_exec (zotonic_core v1.0.0-rc.17)
Execute OS commands with timeouts.
Summary
Functions
Executes the given command in the default shell for the operating system. Run with a default timeout of 15 minutes and a default maximum returned size of 1GB.
Executes the given command in the default shell for the operating system. The option max_data will terminate the program after more data than the given number of bytes is received. Use 'infinity' to not restrict the output size. The option timeout will terminate the program if more time than the given milliseconds have passed, in that case {error, timeout} is returned.
Types
-type os_command() :: iodata().
-type os_command_opts() :: #{max_size => non_neg_integer() | infinity, timeout => non_neg_integer()}.
Functions
-spec run(Command) -> {ok, Data} | {error, Reason} when Command :: os_command(), Data :: binary(), Reason :: term().
Executes the given command in the default shell for the operating system. Run with a default timeout of 15 minutes and a default maximum returned size of 1GB.
-spec run(Command, Options) -> {ok, Data} | {error, Reason} when Command :: os_command(), Options :: os_command_opts(), Data :: binary(), Reason :: term().
Executes the given command in the default shell for the operating system. The option max_data will terminate the program after more data than the given number of bytes is received. Use 'infinity' to not restrict the output size. The option timeout will terminate the program if more time than the given milliseconds have passed, in that case {error, timeout} is returned.