What error code is that?
$ ocaml -I +unix unix.cma -e 'print_endline (Unix.error_message (EUNKNOWNERR 10))' No child processes
Perl equivalent:
$ perl -le '$!=10; print $!' No child processes
No longer a oneliner, but if you want the readable code:
#! /usr/bin/env -S thin-ocamlscript -package core,core_unix -linkpkg --
let () =
let errno = int_of_string Sys.argv.(1) in
let e = Core_unix.Error.of_system_int ~errno in
let code = Core.Sexp.to_string_hum (Core_unix.Error.sexp_of_t e) in
let msg = Core_unix.Error.message e in
Printf.printf "%d = %s = %s\n" errno code msg
or, embracing Core instead of only grabbing its convenient derivation:
#! /usr/bin/env -S thin-ocamlscript -package core,core_unix -linkpkg --
open Core
open Core_unix
let () =
let errno = Int.of_string (Sys.get_argv ()).(1) in
let e = Error.of_system_int ~errno in
let code = Sexp.to_string_hum (Error.sexp_of_t e) in
let msg = Error.message e in
Printf.printf "%d = %s = %s\n" errno code msg