Skip to content

Instantly share code, notes, and snippets.

@Sushisource
Last active December 18, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sushisource/5703251 to your computer and use it in GitHub Desktop.
Save Sushisource/5703251 to your computer and use it in GitHub Desktop.
Nonzero status codes take are never received
-module(command).
-compile(export_all).
command(Cmd) ->
Opt = [stream, exit_status, use_stdio,
stderr_to_stdout, in, eof],
P = open_port({spawn, Cmd}, Opt),
get_data(P, []).
get_data(P, D) ->
receive
{P, eof} ->
Status = receive
{P, {exit_status, N}} -> N
after 3000 -> timeout
end,
port_close(P),
{Status, lists:flatten(D)};
{P, {data, D1}} ->
get_data(P, [D|D1])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment