summaryrefslogtreecommitdiff
path: root/src/rabbit_control_main.erl
diff options
context:
space:
mode:
authorTim Watson <tim@rabbitmq.com>2012-06-05 12:45:44 +0100
committerTim Watson <tim@rabbitmq.com>2012-06-05 12:45:44 +0100
commit938ccdeb9ccfa348e3fab09d7beecd39c88d9c58 (patch)
treee43ec6eeaba30862bbb838a6f575829abaad9ee5 /src/rabbit_control_main.erl
parent5f3b10ba554ca65b7098cb1abfd8f40f317a8a97 (diff)
downloadrabbitmq-server-938ccdeb9ccfa348e3fab09d7beecd39c88d9c58.tar.gz
capture and swallow all stdio during 'rabbitmqctl wait'
Diffstat (limited to 'src/rabbit_control_main.erl')
-rw-r--r--src/rabbit_control_main.erl20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/rabbit_control_main.erl b/src/rabbit_control_main.erl
index 29408006..bce20e88 100644
--- a/src/rabbit_control_main.erl
+++ b/src/rabbit_control_main.erl
@@ -511,8 +511,7 @@ read_pid_file(PidFile, Wait) ->
% rpc:call(os, getpid, []) at this point
process_up(Pid) ->
with_os([{unix, fun () ->
- system("ps -p " ++ Pid
- ++ " >/dev/null 2>&1") =:= 0
+ system("ps -p " ++ Pid) =:= 0
end},
{win32, fun () ->
Res = os:cmd("tasklist /nh /fi \"pid eq " ++
@@ -532,13 +531,16 @@ with_os(Handlers) ->
% Like system(3)
system(Cmd) ->
- ShCmd = "sh -c '" ++ escape_quotes(Cmd) ++ "'",
- Port = erlang:open_port({spawn, ShCmd}, [exit_status,nouse_stdio]),
- receive {Port, {exit_status, Status}} -> Status end.
-
-% Escape the quotes in a shell command so that it can be used in "sh -c 'cmd'"
-escape_quotes(Cmd) ->
- lists:flatten(lists:map(fun ($') -> "'\\''"; (Ch) -> Ch end, Cmd)).
+ Port = erlang:open_port({spawn, Cmd},
+ [exit_status,{line, 16384},
+ use_stdio, stderr_to_stdout]),
+ exit_loop(Port).
+
+exit_loop(Port) ->
+ receive
+ {Port, {exit_status, Rc}} -> Rc;
+ {Port, _} -> exit_loop(Port)
+ end.
format_parse_error({_Line, Mod, Err}) ->
lists:flatten(Mod:format_error(Err)).