public Collection getDprcInfo(StringBuffer permid,StringBuffer begDt,StringBuffer endDt) throws InterruptedException{     
        Collection coll = new ArrayList();
        System.out.println("prel");
        String perlCmd = "C:/Scripts/get_sec_dprc_info.pl --Permid "+permid.toString()+" --beg "+begDt.toString()+" --end "+endDt.toString();
        String cmd = "C:\\cygwin\\bin\\bash.exe -lc \"perl "+perlCmd+" \" ";
        System.out.println(cmd);
       
        try {
            Process process;
            String line;
            process = Runtime.getRuntime().exec(cmd);            
            BufferedReader prcout = new BufferedReader(
            new InputStreamReader(
            new BufferedInputStream(process.getInputStream())),50);              while ((line=prcout.readLine()) != null){ 
                coll.add(line);                                 process.waitFor();               
            }   prcout.close();
                 prcout.close();
                                    
        } catch (IOException ex) {
            ex.printStackTrace();
        }       
            return coll;           
    }我需要在java中调用外部命令利用cygwin\\bin\\bash.exe 执行一条脚本语句!脚本是查询数据库中的数据,脚本中有3个参数!当我需要查询2个日期间的数据时,输入7天内的数据可以查询出结果!但是如果查询较长时期的数据 就会在while ((line=prcout.readLine()) != null) 卡住!无异常 无错,有可能是缓冲问题!!!!!但是一直无法解决!!!希望高手帮忙 

解决方案 »

  1.   

    输出大概有不到30条记录! 但是在DOS下可以正常执行!
      

  2.   

     process = Runtime.getRuntime().exec(cmd);        
    这个命令很疆的,以前我用这个东西做做copy都会出问题。估计你上面的脚本还没运行完。java已经跑到下面执行 while ((line=prcout.readLine()) != null){ 在process = Runtime.getRuntime().exec(cmd);下面sleep一下看看呢?  
      

  3.   

    那这样的话效率也太低了!听你这么说到有可能 因为perl脚本要执行完才返回!
      

  4.   

    我看了问题确实是在process   =   Runtime.getRuntime().exec(cmd);这个的问题!出现了假死状态!
    但是还是无法解决