cnd
cnd

Reputation: 33764

How to detect running operating system?

How can I detect system type / operating system in OCaml ?

My current idea is really weird. Running system call : "uname -a" with

let syscall ?(env=[| |]) cmd =
    let ic, oc, ec = Unix.open_process_full cmd env in
    let buf1 = Buffer.create 96
    and buf2 = Buffer.create 48 in
    (try
     while true do Buffer.add_channel buf1 ic 1 done
    with End_of_file -> ());
    (try
     while true do Buffer.add_channel buf2 ec 1 done
    with End_of_file -> ());
    let exit_status = Unix.close_process_full (ic, oc, ec) in
    check_exit_status exit_status;
    (Buffer.contents buf1,
    Buffer.contents buf2)

even on cygwin ...

But I guess there must be some native for ocaml way to check system type.

Upvotes: 5

Views: 809

Answers (2)

ygrek
ygrek

Reputation: 6697

NB there is also a wrapper for uname in extunix

Upvotes: 2

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66813

The standard OCaml library has a string named Sys.os_type, but it doesn't contain as much information as uname -a. It is either "Unix", "Win32", or "Cygwin". It's described in the manual entry for the Sys module.

Upvotes: 5

Related Questions