Detecting Operating Systems

BlitzMax Forums/BlitzMax Beginners Area/Detecting Operating Systems

cps(Posted 2016) [#1]
If HostName(HostIp ("", 0))="" then'you are on a MAC (OSX)

else' you are on a PC (win)

end if


grable(Posted 2016) [#2]
Why do a non-standard/undocumented runtime check for something that is guaranteed to be known at compile time?


cps(Posted 2016) [#3]
Opps! I seem to have started two threads, sorry.( I hit the tab key) To reply to your question.
Using the above I can use one source code and compile on either system without making any edits. As these edits are spread around I may miss one.
Have fun Cps


grable(Posted 2016) [#4]
And so will
?MacOS
Print "MAC"
?Win32
Print "WIN"
?
Or if you want runtime checks
Const MAC = 0
Const WIN = 1
?MacOS
Global Platform:Int = MAC
?Win32
Global Platform:Int = WIN
?

If Platform = MAC Then
...
But after reading your other post i see you meant alternate uses for popular functions so maybe its not so bad :p Just know it might change any time hehe


cps(Posted 2016) [#5]
You may find this hard to belive (or not) but I've never come across ?Mac or ?Win32 is there a ?Linux ? ( is this documented somewhere ?)
Thanks for the info I'll apply your solution to my code, have fun Cps


grable(Posted 2016) [#6]
Yes, there are a few of them.

They are documented in MaxIDE, via the "home page".. Language reference -> Conditional compiling


cps(Posted 2016) [#7]
Many, many thanks I never looked under 'conditional compiling' but it's all there.
As an aside have you ever found a way of getting the Mac OSX local computer name, other than using one of 'Brucy's modules?
It was looking for a solution to this that lead me down this route. At the moment if OS is Mac based I get the user to input the local computer name.
Thanks again for your input, if I hadn't posted my daft solution to finding the OS I would never have found the correct solution. Have fun Cps


skidracer(Posted 2016) [#8]
If you are using MaxGUI then you can use the undocumented UserName$() and ComputerName$() functions which were added in BlitzMax 1.50.


xlsior(Posted 2016) [#9]
Keep in mind, your sample will also tell you that you're on a Mac when you're really on a PC without network access. ;-)


cps(Posted 2016) [#10]
Thanks for the input.
simonarmstrong : print computername$ (on a mac) returns the computer name and not the local computer name. IE not the one that ends .local
I'm trying some variations to see if I can find another undocumented function that will return this variable or even the local IP which I want to derive from this var.
Xisor : Thanks for the reminder I hope to avoid this problem by letting the user know that the games are for networked computers only.
Thanks again for the feedback which will come in very handy, have fun Cps


cps(Posted 2016) [#11]
After a bit of a tinkering I found that the difference between my mac computer name and the network (.local) name was that the spaces had been replaced by - and .local added.
If this is universal (common to mac OSX) then problem solved. IE (if using MaxGui)
LocalMacName$=replace(ComputerName$," ","-")+".local" and
DottedIP$=DottedIP(HostIp(LocalMacName$))
I'll post this to the MAC OSX forum and see if any Mac users can find fault with this. Again many thanks for the input, have fun Cps