[Mono-osx] OSX vs Linux
Gavin Landon
Gavin.Landon at ignitetech.com
Fri Dec 14 14:29:50 EST 2007
LoL.. A coworker and I was talking about how else it was possible and
had mentioned going to the file level. That's funny.
Thanks
-----Original Message-----
From: russell.kay at realtimeworlds.com
[mailto:russell.kay at realtimeworlds.com]
Sent: Friday, December 14, 2007 11:45 AM
To: Gavin Landon; mono-osx at lists.ximian.com
Subject: RE: [Mono-osx] OSX vs Linux
Currently we use the following function (note C Sharp code)
//
---------------------------------------------------------------
static private string getMachineType()
{
string ret = "unknown";
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
ret = "Unix";
// need to execute uname -s to find out if it is a MAC
or not
StringBuilder output = new StringBuilder();
int nRet = execute("uname -s", output);
if ((nRet == 0) &&
(output.ToString().StartsWith("Darwin"))) {
ret = "Mac";
} // end if
break;
case PlatformID.Win32NT:
ret = "WinNT";
break;
case PlatformID.Win32S:
ret = "Win32s";
break;
case PlatformID.Win32Windows:
ret = "Win95+";
break;
case PlatformID.WinCE:
ret = "WinCE";
break;
} // end switch
return ret;
} // end getMachineType
Where the execute call is
//
---------------------------------------------------------------
static public int execute(string _command, StringBuilder
_output)
{
int ret = -1;
Process proc = new Process();
int firstSpaceIndex = _command.IndexOf(' ');
string command = _command.Substring(0, firstSpaceIndex);
string commandLine = _command.Substring(firstSpaceIndex);
proc.StartInfo.FileName = command;
proc.StartInfo.Arguments = commandLine;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
// redirect output if we want to
ms_output = _output;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.OutputDataReceived += new
DataReceivedEventHandler(outputDataReceived_static);
proc.ErrorDataReceived += new
DataReceivedEventHandler(errorDataReceived_static);
try {
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
proc.WaitForExit();
ret = proc.ExitCode;
proc.Close();
} // end try
catch (Exception _e) {
if (_output != null) {
_output.AppendFormat("Exception \"{0}\"\nfor {2}
{3}\nStack Trace{1}", _e.Message, _e.StackTrace, command, commandLine);
} // end if
ret = -1;
} // end catch
ms_output = null;
return ret;
} // end execute
//
---------------------------------------------------------------
static void errorDataReceived_static(object sender,
DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data)) {
if (ms_output != null) {
ms_output.AppendFormat("{0}{1}", e.Data,
Environment.NewLine);
} // end if
} // end if
}
//
---------------------------------------------------------------
static void outputDataReceived_static(object sender,
DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data)) {
if (ms_output != null) {
ms_output.AppendFormat("{0}{1}", e.Data,
Environment.NewLine);
} // end if
} // end if
} // end execute
And this works for us... though it would fail on a non-MacOSX Darwin
machine... not too many of them I think.
Russell
-----Original Message-----
From: mono-osx-bounces at lists.ximian.com
[mailto:mono-osx-bounces at lists.ximian.com] On Behalf Of Gavin Landon
Sent: 14 December 2007 17:14
To: mono-osx at lists.ximian.com
Subject: Re: [Mono-osx] OSX vs Linux
Well, the only thing I can come up with is looking at the version
itself. Of course this method will have be changed and the Major bumped
up as Linux catches up..
------------------
static public string GetOS()
{
int p = (int) Environment.OSVersion.Platform;
int v = (int) Environment.OSVersion.Version.Major;
if(Environment.OSVersion.Platform.ToString()=="Win32NT")
return "Windows";
if ((p == 4) || (p == 128)) {
if(v<8)
return "Unix";
else
return "OSX";
}
return "Unknown";
}
-----Original Message-----
From: mono-osx-bounces at lists.ximian.com
[mailto:mono-osx-bounces at lists.ximian.com] On Behalf Of Gavin Landon
Sent: Friday, December 14, 2007 10:30 AM
To: mono-osx at lists.ximian.com
Subject: [Mono-osx] OSX vs Linux
I'm having some trouble distinguishing the difference between Linux and
OSX.
I have a test method I'm using to try different things out and both OSX
and Linux come back with "Unix" as the text and p="4". The only
difference is OSVersion will return a much lower version number on Linux
that on Mac. Is there another way to tell?
------------------
static public string GetOS()
{
int p = (int) Environment.OSVersion.Platform;
MessageBox.Show("Environment.OSVersion.Version: " +
Environment.OSVersion.Version.ToString());
MessageBox.Show("Environment.OSVersion: " +
Environment.OSVersion.ToString());
MessageBox.Show("OS Version: " +
Environment.OSVersion.Platform.ToString() + " #" + p.ToString());
if(Environment.OSVersion.Platform.ToString()=="Win32NT")
return "Windows";
if ((p == 4) || (p == 128)) {
return "Unix";
} else {
return "Not Unix";
}
}
_______________________________________________
Mono-osx mailing list
Mono-osx at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-osx
_______________________________________________
Mono-osx mailing list
Mono-osx at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-osx
____________________________________________________________________
This email has been scanned by the MessageLabs Email Security System
DISCLAIMER
This message and any attachments contain privileged and confidential
information intended for the use of the addressee named above. If you
are not the intended recipient of this message, you are hereby notified
that any use, dissemination, distribution or reproduction of this
message is prohibited. Please note that we cannot guarantee that this
message or any attachment is virus free or that it has not been
intercepted and amended. The views of the author may not necessarily
reflect those of Real Time Worlds Ltd.
____________________________________________________________________
This email has been scanned by the MessageLabs Email Security System
More information about the Mono-osx
mailing list