diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-07-06 19:14:37 -0400 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-07-06 19:14:37 -0400 |
commit | df45aa6d48b15fcd9b5a62b0c4fef17ddae3d8ee (patch) | |
tree | c9cf84c53156f60cc040cd554f2548afb47ec049 /src | |
parent | 632f2dd304cc9dbd280711424985684fa8ada365 (diff) | |
parent | d64cb0f86382e8c8040c6ac507fd32ec06b7389c (diff) |
Merge pull request #591 from tsloughter/589
always close port when done with it. fixes #589
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_utils.erl | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 1cd6694..ebdf0fe 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -128,11 +128,13 @@ sh_send(Command0, String, Options0) -> PortSettings = proplists:get_all_values(port_settings, Options) ++ [exit_status, {line, 16384}, use_stdio, stderr_to_stdout, hide], Port = open_port({spawn, Command}, PortSettings), - - %% allow us to send some data to the shell command's STDIN - %% Erlang doesn't let us get any reply after sending an EOF, though... - Port ! {self(), {command, String}}, - port_close(Port). + try + %% allow us to send some data to the shell command's STDIN + %% Erlang doesn't let us get any reply after sending an EOF, though... + Port ! {self(), {command, String}} + after + port_close(Port) + end. %% %% Options = [Option] -- defaults to [use_stdout, abort_on_error] @@ -159,11 +161,15 @@ sh(Command0, Options0) -> ?DEBUG("Port Cmd: ~s\nPort Opts: ~p\n", [Command, PortSettings]), Port = open_port({spawn, Command}, PortSettings), - case sh_loop(Port, OutputHandler, []) of - {ok, _Output} = Ok -> - Ok; - {error, {_Rc, _Output}=Err} -> - ErrorHandler(Command, Err) + try + case sh_loop(Port, OutputHandler, []) of + {ok, _Output} = Ok -> + Ok; + {error, {_Rc, _Output}=Err} -> + ErrorHandler(Command, Err) + end + after + port_close(Port) end. find_files(Dir, Regex) -> |