2012-01-23 16 views
6

Come posso rilevare il tipo di sistema/sistema operativo in OCaml?Come rilevare il sistema operativo in esecuzione?

La mia idea attuale è davvero strana. Esecuzione di chiamata di sistema: "uname -a" con

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) 

anche su cygwin ...

Ma credo che ci deve essere qualche modo nativo per OCaml per controllare il tipo di sistema.

risposta

6

La libreria OCaml standard ha una stringa denominata Sys.os_type, ma non contiene il numero di informazioni come uname -a. È "Unix", "Win32" o "Cygwin". È descritto in the manual entry for the Sys module.

Problemi correlati