package com.kun.util;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class TestOSPath { static Process process;
public static void main(String[] args) {
try {
String[] cmd = new String[] { "cmd.exe", "/c", "path" };
process = Runtime.getRuntime().exec(cmd);
InputStreamReader ir = new InputStreamReader(process
.getInputStream());
BufferedReader br = new BufferedReader(ir);
String line;
String path="";
while ((line = br.readLine()) != null){
path+=line;
}
System.out.println(path);
path=path.substring(path.indexOf("=")+1).toLowerCase();
String[] temp=path.split(";");
for(int i=0;i<temp.length;i++){
if(temp[i].indexOf("windows")!=-1){
path=path.substring(0,temp[i].indexOf(":"));
break;
}
}
System.out.println(path);
}
catch (java.io.IOException e) {
System.err.println("IOException " + e.getMessage());
e.printStackTrace();
}
}
}