Linux - Obtain environment variables

P

pd

guys,

under linux, how can java access environment variables. currently i
have something like,
Properties envVars = new Properties();
Runtime r = Runtime.getRuntim();
Process p = null;
p = r.exec("env");

and this doesnt work. does anybody know how to get this to work.
thanks a lot.
 
S

stefanomnn

guys,

under linux, how can java access environment variables. currently i
have something like,
Properties envVars = new Properties();
Runtime r = Runtime.getRuntim();
Process p = null;
p = r.exec("env");

and this doesnt work. does anybody know how to get this to work.
thanks a lot.

Hello!
Did you try taking input stream from process?
 
G

Gordon Beaton

under linux, how can java access environment variables. currently i
have something like,
Properties envVars = new Properties();
Runtime r = Runtime.getRuntim();
Process p = null;
p = r.exec("env");

and this doesnt work. does anybody know how to get this to work.

"Something like" doesn't help anyone debug your real code.

Try using Properties.load(InputStream), passing the p.getInputStream()
as the argument.

If that doesn't work, post a complete example.

/gordon

--
 
S

stefanomnn

if you run on java 1.5,
you needn't use Process class,
toy can use System.getEnvs() method,
which return you a map of all environnement settings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top