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

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top