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

1

11

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?

Whipcord answered 20/1, 2009 at 11:58 Comment(3)
seriously? I was here first...Whipcord
The other question has a much better answer by today's standards of SO, and it was suggested as duplicate of this. It makes more sense to have duplicate this way. No offence meant in any way.Elasticity
none taken, I'm mostly bewildered and amused. Thanks for the explanation. The other question specifically states that this here accepted answer does not solve the problem. what makes people think it's the same thing?Whipcord
A
29

Try System.getenv(String name)

Ayeaye answered 20/1, 2009 at 12:1 Comment(2)
Although if you are still using 1.4 (which has end of lifed, but there's still paid support available), it will throw an Error.Lambdacism
That doesn´t seem to get the env variables setup in .bashrc or .profile. Does it only load the system environment variables?Cush

© 2022 - 2024 — McMap. All rights reserved.