Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can my Java code read OS environment variables? [duplicate]

This may be a very simple problem, but I couldn't find an answer googleing and I'm in a rush - so I'd appreciate fast code examples.

I have an environment variable on the OS I would like to read using Java code. I've tried System.getProperty, but that only seems to work for the -D variables supplied directly for the JVM.

How can my Java code read OS variables?

like image 927
Amir Arad Avatar asked Jan 20 '09 11:01

Amir Arad


People also ask

How do you get all available operating system environment variables in Java?

There are two ways to get the environment variable in Java, by using System properties or by using System. getEnv(). System properties provide only a limited set of predefined environment variables like java. classpath, for retrieving Java Classpath or java.

How do I read all environment variables?

To list all the environment variables, use the command " env " (or " printenv "). You could also use " set " to list all the variables, including all local variables.

How do you get all environment variables and how can you use them?

You can use any one of the following command to display and list the shell environment variables and their values. The printenv command list the values of the specified environment VARIABLE(s). If no VARIABLE is given, print name and value pairs for them all. printenv command – Print all or part of environment.


1 Answers

Try System.getenv(String name)

like image 98
bruno conde Avatar answered Oct 06 '22 00:10

bruno conde