Wish i had a better idea how to do that
authormalc <av1474@comtv.ru>
Sun, 2 Jun 2013 16:03:49 +0000 (2 20:03 +0400)
committermalc <av1474@comtv.ru>
Sun, 2 Jun 2013 16:07:50 +0000 (2 20:07 +0400)
main.ml

diff --git a/main.ml b/main.ml
index 2928058..f9c8355 100644 (file)
--- a/main.ml
+++ b/main.ml
@@ -7592,6 +7592,31 @@ let () =
 
   setcheckers conf.checkers;
   redirectstderr ();
+  if conf.redirectstderr
+  then
+    at_exit (fun () ->
+      let s = Buffer.contents state.errmsgs ^
+        (match state.errfd with
+        | Some fd ->
+            let s = String.create (80*24) in
+            let n =
+              try
+                let r, _, _ = Unix.select [fd] [] [] 0.0 in
+                if List.mem fd r
+                then Unix.read fd s 0 (String.length s)
+                else 0
+              with _ -> 0
+            in
+            if n = 0
+            then ""
+            else String.sub s 0 n
+        | None -> ""
+        )
+      in
+      try ignore (Unix.write state.stderr s 0 (String.length s))
+      with exn -> print_endline (exntos exn)
+    )
+  ;
 
   init (cr, cw) (
     conf.angle, conf.fitmodel, (conf.trimmargins, conf.trimfuzz),