Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.25 KB | None | 0 0
  1. module Colab.Core.OS
  2.  
  3. open System
  4. open System.Diagnostics
  5.  
  6. type Version =
  7.  | Windows
  8.  | Unix
  9.  | OSX
  10.  | Unknown
  11.  
  12. let isDarwin = ref None
  13.  
  14. let queryUname() =
  15.     try
  16.         let proc = new Process()
  17.         let info = new ProcessStartInfo("uname", "-a")
  18.         info.RedirectStandardOutput <- true
  19.         info.WindowStyle <- ProcessWindowStyle.Hidden
  20.         info.UseShellExecute <- false
  21.         info.CreateNoWindow <- true
  22.         proc.StartInfo <- info
  23.         proc.Start() |> ignore
  24.         let output = proc.StandardOutput.ReadToEnd()
  25.         proc.WaitForExit()
  26.         isDarwin := Some(output.Contains("Darwin Kernel"))
  27.     with
  28.      | _ ->
  29.         ()
  30.  
  31. let isWindows() =
  32.     Environment.OSVersion.Platform = PlatformID.Win32S ||
  33.     Environment.OSVersion.Platform = PlatformID.Win32NT ||
  34.     Environment.OSVersion.Platform = PlatformID.Win32Windows ||
  35.     Environment.OSVersion.Platform = PlatformID.WinCE ||
  36.     Environment.OSVersion.Platform = PlatformID.Xbox
  37.  
  38. let version =
  39.     if isWindows() then Windows
  40.     else
  41.         queryUname()
  42.         match !isDarwin with
  43.          | Some(darwin) -> if darwin then OSX else Unix
  44.          | None -> Unknown
  45.  
  46. let isPosix = match version with | Unix -> true | OSX -> true | _ -> false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement