Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Windows or Linux? [duplicate]

I am seeking to run a common Java program in both Windows and Linux.

The program needs to do some things differently on each platform.

So how can / should my Java program detect it is running under Linux vs. Windows?

like image 357
Ron Whites Avatar asked Jan 11 '13 23:01

Ron Whites


People also ask

How do I know if I have Windows or Linux?

Click the "Start" button if there is one. A Microsoft Windows logo or flag may mean you have a version of Windows that predates Windows 95, such as Windows 3.11. If you see a red hat in a corner of your screen, you are running the Red Hat Linux operating system.

How do I know my Java operating system?

Use the System. getProperty() method in Java to get the Operating System name.

How do I get the OS name in C++?

h> int uname(struct utsname *name);


2 Answers

apache commons lang has a class SystemUtils.java you can use :

SystemUtils.IS_OS_LINUX SystemUtils.IS_OS_WINDOWS 
like image 141
othman Avatar answered Oct 05 '22 14:10

othman


Try:

System.getProperty("os.name"); 

http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties%28%29

like image 44
Puce Avatar answered Oct 05 '22 15:10

Puce