Hi Yoddi,
The example code you submitted may have some issues
[[[
String s = null;
try
{
Process pr = Runtime.getRuntime().exec("CMD /c \"echo %systemroot%\"");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(pr.getInputStream()));
if ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
catch (Exception e)
{
System.err.println ("Error ....");
}
}
]]]
One has to read Exec'd process output/error stream as well -- incase any error/etc, in separate
thread to make this exec-stuff work properly all the times.
Another simple solution (instead of costly exec) is use to System.getenv(EN_VAR). This method is available since 1.2 onwards(but deprecated till JDK 1.5).So to reduce no of deprecated warnings in your code(for pre JDK 1.4 code), pass it thru a wrapper-class/method . By using wrapper you will get deprecated warning only once for compilation.