C# System.PlatformID.Unix vs. Linux
Question:
I need to make some system calls in my C# applications. Unfortunately, this behaves differently on Linux than on UNIX.
Now I used to switch the Operating system at runtime like this
If Environment.OSVersion.Platform = Sy开发者_StackOverflow中文版stem.PlatformID.Unix Then
' Linux/Unix '
ElseIf Environment.OSVersion.Platform = System.PlatformID.MacOSX Then
' Apple '
Else
' Windows '
End If
The problem now is I need to differentiate between UNIX and Linux, because they are different.
Is there a way I can figure out whether the OS is Linux or Unix? Preferably not by invoking uname -a
I wouldn't like to abandon Unix and make it Linux only, just because Microsoft did not add a PlatformID.Linux...
You will need to use "uname -a" to distinguish Linux from Unix, as well as OSX. For historical reasons, Mono reports OSX as Unix, not MacOSX.
Some code that uses uname is available here: http://github.com/jpobst/Pinta/blob/master/Pinta/Platform.cs
精彩评论