Erlcmd includes a simple tool function cmd:run
. It likes os:cmd
but returns exit status code and stdio output.
Download src/cmd.erl to your local disk then run:
Exe = os:find_executable("ls"),
CmdLine = Exe ++ " -a ./src",
{ok, ExitStatus, Output} = cmd:run(CmdLine, 1000),
io:format("exit status code: ~p~noutput: ~n~s", [ExitStatus, Output]).
Or like this:
Exe = os:find_executable("ls"),
{ok, ExitStatus, Output} = cmd:run(Exe, ["-a", "./src"], 5000),
io:format("exit status code: ~p~noutput: ~n~s", [ExitStatus, Output]).
Add the following script into your rebar.config if you wanna manage your project by rebar.
{deps, [
{erlcmd, "*", {git, "https://github.com/pzlib/erlcmd.git", {tag, "0.1.0"}}}
]}.