posts - 56, comments - 54, trackbacks - 0, articles - 4
   ::  ::  :: 联系 :: 聚合  :: 管理

jsp页面上调用Batch

Posted on 2006-10-10 15:53 Terry的Blog 阅读(1322) 评论(0)  编辑  收藏 所属分类: java语言web开发

有这样一个需求,web服务器是sun Soaris5.8 原来有一个java写的Batch打包成jar文件由shell调用 现在要在页面上增加一个按钮调用这个shell。
代码如下:
 struts中的Action

public  ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    
throws  Exception {

    String command 
=   " csh /home/zwfe/shell/zwfecv101.csh " ;
    Process child;
    
try  {
        child 
=  Runtime.getRuntime().exec(command);

        BufferedReader in 
=   new  BufferedReader( new  InputStreamReader(child.getInputStream()));
        String line 
=   "" ;
        
while  ((line  =  in.readLine())  !=   null ) {
            System.out.println(line);
        }
        in.close();

    } 
catch  (IOException e) {
        System.out.println(
" e.getMessage() =  "   +  e.getMessage());
        e.printStackTrace();
    }

    BatchDateDAO dao 
=   new  BatchDateDAO();
    Zwfecw002Form zwfe002form 
=  (Zwfecw002Form) form;
    zwfe002form.setBatchDate(dao.batchDate());

    
return  mapping.findForward( " screen.zwfecw002 " );
}

这里应该注意child = Runtime.getRuntime().exec(command);后需要检查这个Process 是否已经执行完毕,否则当Action执行完返回后Process 将会中断。


只有注册用户登录后才能发表评论。


网站导航: