2

I know there's Sys.os_type but it lumps OSX, Linux, etc. all under the same category. I'd like to detect the OS and most importantly distinguish between OSX and Linux.

2
  • 1
    It sounds more like a compile time switch than runtime thing. Have you considered that at all? Commented Apr 11, 2014 at 13:33
  • 1
    I have. Either approach could work but I'm not using optcomp or any other pre processor currently so I'd prefer not to introduce that unless absolutely necessary. Commented Apr 11, 2014 at 13:57

1 Answer 1

4

You could try something like this:

# let ic = Unix.open_process_in "uname" in
  let uname = input_line ic in
  let () = close_in ic in
  uname;;
- : string = "Darwin"

In OSX it returns "Darwin". In Linux it returns "Linux" (at least that's what I saw just now when I tried).

I don't know the behavior on Windows. But at least it will be different :-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.