2012-01-23 19 views
6

¿Cómo puedo detectar el tipo de sistema/sistema operativo en OCaml?¿Cómo detectar el sistema operativo en ejecución?

Mi idea actual es realmente extraña. Ejecución de la llamada al 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) 

incluso en cygwin ...

Pero supongo que debe haber alguna forma nativa para ocaml para comprobar el tipo de sistema.

Respuesta

6

La biblioteca OCaml estándar tiene una cadena llamada Sys.os_type, pero no contiene tanta información como uname -a. Es "Unix", "Win32" o "Cygwin". Se describe en the manual entry for the Sys module.

Cuestiones relacionadas