I’m happy to announce the first release of out-channel-redirect, a library for redirecting and capturing output written to out_channels.
Features:
- Capture any out_channel into a string (with convenience shorthands for stdout and stderr)
- Redirect one channel into another
- Works on native (via dup/dup2), JavaScript (js_of_ocaml), and WebAssembly (wasm_of_ocaml)
- Expert API for manual redirection lifetime control
Installation:
opam install out-channel-redirect
Quick example:
let output, result =
Out_channel_redirect.capture_channel some_channel ~f:(fun () →
Printf.fprintf some_channel “hello”;
42)
(* output = “hello”, result = 42 *)