java - Can I set environment variables from code? -


this question has answer here:

i trying install apche tomcat. there arises need set environment variable's , how can set environment variable?

i tried using processbuilder doesn't work:

processbuilder pb = new processbuilder("cmd.exe", "/c", "set"); // set prints out environment variables   pb.redirecterrorstream(true);   map<string,string> env = pb.environment();   string path = env.get("catalina_home") + apachepath; env.put("catalina_home", path);   process process = null; try {     process = pb.start(); } catch (ioexception e) {     // todo auto-generated catch block     e.printstacktrace(); } 

example here:

import java.io.*;   import java.util.*;    public class test   {       public static void main(string[] args) throws exception       {           processbuilder pb = new processbuilder("cmd.exe", "/c", "set"); // set prints out environment variables           pb.redirecterrorstream(true);           map<string,string> env = pb.environment();           string path = env.get("path") + ";c:\\naved\\bin";           env.put("path", path);           process process = pb.start();           bufferedreader in = new bufferedreader(new inputstreamreader(process.getinputstream()));           string line;           while ((line = in.readline()) != null)           {               system.out.println(line);           }       }   }  

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -