java shell echo 环境变量

   /**
    * java调用shell命令获取路径
    * @return
    */
   private String  getHomePathName(){
        Process process = null;
        BufferedReader input = null;
        List processList = new ArrayList();
        try {
            //linux
            String[] cmdline = { "sh", "-c", "echo  "+financedocumentsHomePath }; 
            //Windows 
//          String[] cmdline = { "cmd.exe", "-c", "java -version"}; 
            ProcessBuilder pb=new ProcessBuilder(cmdline);
            process= pb.start();
            input = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = "";
            while ((line = input.readLine()) != null) {
                processList.add(line);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(input!=null){
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        String homePathName="";
        if(processList!=null && processList.size()>=0){
            for (String string : processList) {
                homePathName+=string;
            }
        }
        log.info("****************************财务单据报表家路径:"+homePathName+"************");
        return homePathName;
   }

你可能感兴趣的:(java,java,shell)