We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Checking OS? (Read 467 times)
Checking OS?
Jul 10th, 2009, 9:20pm
 
I'm fairly new to programming in Processing and Java.

I've noticed that when I run one of my Processing applications in Windows versus Linux I'm setting up my serial port settings differently
Serial.list()[0] when running Ubuntu
Serial.list()[1] when running Windows Vista

Instead of changing my source code each time is there a way in processing to find out which OS is running my program?

Vince.
Re: Checking OS?
Reply #1 - Jul 11th, 2009, 12:20am
 
I don't think it is OS specific only, it can be also computer specific (what ports exists and are available, etc.).
Now, if you just want a convenience way for your own computer, you can use the result of System.getProperty("os.name");

Ah, just checked, even easier, use platform variable! It is set to one of:
OTHER  
WINDOWS
MACOSX
LINUX  
constants.
Re: Checking OS?
Reply #2 - Jul 11th, 2009, 1:02am
 
PhiLho  wrote on Jul 11th, 2009, 12:20am:
Ah, just checked, even easier, use platform variable! It is set to one of:
OTHER  
WINDOWS
MACOSX
LINUX  
constants.



Ok, I added these lines to my code

 int myPlatform;
 myPlatform = platform;
 println(myPlatform);

and it prints out 1 when running my Windows Vista OS, I haven't tried Linux yet.

I checked the Processing.org site for documentation on the "platform" variable but didn't have much luck finding it yet. Is this an intrinsic variable supplied by Java  Any suggestions about where to find information about this variable

This is more of a quick check when I'm testing between OS's so I don't have to change the code each time.

Thanks for the help.
Re: Checking OS?
Reply #3 - Jul 11th, 2009, 1:29am
 
No need to duplicate the variable (which is specific to Processing). And these are constants, that doesn't mean these are strings. You get the strings with the System call I shown.
You can do stuff like: Code:
switch (platform)
{
case WINDOW:
 port = 1;
 break;
case LINUX:
 port = 0;
 break;
default:
 println("I don't know what to do");
 exit()
}
for example.
Page Index Toggle Pages: 1