| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1498 人关注过本帖
标题:怎样实现用Java执行cmd命令,然后获取cmd的输出
只看楼主 加入收藏
windyfzz
Rank: 2
等 级:禁止访问
帖 子:90
专家分:12
注 册:2010-7-25
结帖率:68%
收藏
 问题点数:0 回复次数:0 
怎样实现用Java执行cmd命令,然后获取cmd的输出
File file=new File(strName+".java");
                        FileOutputStream fos=new FileOutputStream(file);
                        OutputStreamWriter osr=new OutputStreamWriter(fos);
                        BufferedWriter bw=new BufferedWriter(osr);
                        bw.write(text.getText());
                        bw.close();
                        
                        
                        String cmd = "javac ";
                        String param =file.getName();
                        
                        Process child = Runtime.getRuntime().exec(cmd+param); //没有输出
                        //Process   child   =   Runtime.getRuntime().exec( "ipconfig   /all ");   //输出正常
                        try{ Thread.sleep(1000);}
                        catch(Exception ex){ex.printStackTrace();}
                        
                        InputStream is = child.getInputStream();
                        InputStreamReader isr=new InputStreamReader(is);
                        
                        BufferedReader br=new BufferedReader(isr);

                        String str="";
                        while ((str=br.readLine())!=null)
                        {
                           
                            editInformation=editInformation+str+"\r\n";
                        }
                      System.out.println(editInformation);
                      br.close();


  Process child = Runtime.getRuntime().exec(cmd+param); //没有输出
  //Process   child   =   Runtime.getRuntime().exec( "ipconfig   /all ");   //输出正常
 为什么啊?  怎样才能正常输出?

搜索更多相关主题的帖子: java Java 
2011-03-08 23:48
快速回复:怎样实现用Java执行cmd命令,然后获取cmd的输出
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044308 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved