|
@@ -162,6 +162,27 @@ let run_command ctx cmd =
|
|
if len > 3 && String.sub cmd 0 3 = "cd " then begin
|
|
if len > 3 && String.sub cmd 0 3 = "cd " then begin
|
|
Sys.chdir (String.sub cmd 3 (len - 3));
|
|
Sys.chdir (String.sub cmd 3 (len - 3));
|
|
0
|
|
0
|
|
|
|
+ (* Emit stderr as a server message in server mode *)
|
|
|
|
+ end else if CompilationServer.runs() then begin
|
|
|
|
+ let binary_string s =
|
|
|
|
+ if not Globals.is_windows then s else String.concat "\n" (Str.split (Str.regexp "\r\n") s)
|
|
|
|
+ in
|
|
|
|
+ let pout, pin, perr = Unix.open_process_full cmd (Unix.environment()) in
|
|
|
|
+ let bout = Buffer.create 0 in
|
|
|
|
+ let berr = Buffer.create 0 in
|
|
|
|
+ let read_content channel buf =
|
|
|
|
+ Buffer.add_string buf (IO.read_all (IO.input_channel channel));
|
|
|
|
+ in
|
|
|
|
+ let tout = Thread.create (fun() -> read_content pout bout) () in
|
|
|
|
+ read_content perr berr;
|
|
|
|
+ Thread.join tout;
|
|
|
|
+ let result = (match Unix.close_process_full (pout,pin,perr) with Unix.WEXITED c | Unix.WSIGNALED c | Unix.WSTOPPED c -> c) in
|
|
|
|
+ let serr = binary_string (Buffer.contents berr) in
|
|
|
|
+ let sout = binary_string (Buffer.contents bout) in
|
|
|
|
+ if serr <> "" then ctx.messages <- CMError((if serr.[String.length serr - 1] = '\n' then String.sub serr 0 (String.length serr - 1) else serr),null_pos) :: ctx.messages;
|
|
|
|
+ if sout <> "" then ctx.com.print (sout ^ "\n");
|
|
|
|
+ result
|
|
|
|
+ (* Direct pass-through of std streams for normal compilation *)
|
|
end else begin
|
|
end else begin
|
|
match Unix.system cmd with
|
|
match Unix.system cmd with
|
|
| WEXITED c | WSIGNALED c | WSTOPPED c -> c
|
|
| WEXITED c | WSIGNALED c | WSTOPPED c -> c
|