码迷,mamicode.com
首页 > 其他好文 > 详细

QAD 外部调用batch cimload类

时间:2020-10-07 21:13:56      阅读:33      评论:0      收藏:0      [点我收藏+]

标签:close   path   exe   例子   产生   cte   gic   程序   大小   

1.类

 
 /*------------------------------------------------------------------------
    File        : batchcim
    Purpose     : A COMMON CLASS FOR CIMLOAD FROM EXTERNAL PROGRAM
    Syntax      : 
    Description : Compatibility with PROGRESS OPENEDGE 10.1A and above
    Author(s)   : TERRENCE ZHANG
    Created     : Thu Jan 05 15:46:36 CST 2017
    Notes       : Windows Only (use *.bat) Can Convert to Unix Shell
                  Can be invoked by gui/chui/appserver/webspeed 
  ----------------------------------------------------------------------*/

&SCOPED-DEFINE SK + CHR(10) +
/*换行符*/
&SCOPED-DEFINE batname "d:\batchcim\batchcim" 
/*CIM临时文件名称*/
&SCOPED-DEFINE temppath "d:\batchcim\temp\"
/*CIM临时文件夹*/
&SCOPED-DEFINE OEDLC C:\Progress\OpenEdge
/*PROGRESS的安装路径*/
&SCOPED-DEFINE OETMP C:\temp
/*PROGRESS的临时文件夹*/
&SCOPED-DEFINE pfpath d:\batchcim\test.pf    
/*pf文件里有数据库连接字符串等等*/
&SCOPED-DEFINE username "qadcim"
/*登录用户名 权限要有*/
&SCOPED-DEFINE userpsw "123456" 
/*登录密码*/

CLASS batchcim: 
    DEFINE PRIVATE VARIABLE domain AS CHARACTER NO-UNDO.  /*域*/
    DEFINE PUBLIC VARIABLE synex AS LOGICAL NO-UNDO.  /*同步或异步执行 YES-同步*/
    DEFINE PROTECTED VARIABLE bexecp AS CHARACTER NO-UNDO.  /*执行的P程序*/ 
    DEFINE PROTECTED VARIABLE bhcim AS CHARACTER NO-UNDO.  /*linux执行的shell脚本*/
    DEFINE PUBLIC VARIABLE testmode AS LOGICAL NO-UNDO. /*是否为测试模式*/
    DEFINE PROTECTED VARIABLE datalog AS CHARACTER NO-UNDO.
    DEFINE PROTECTED VARIABLE errlog AS CHARACTER NO-UNDO.
    DEFINE PUBLIC VARIABLE mutidm AS LOGICAL INIT YES NO-UNDO.  /*指定的User是否可以访问多个域*/
    
    CONSTRUCTOR PUBLIC batchcim(INPUT edomain AS CHARACTER):
        ASSIGN domain = edomain.
    END CONSTRUCTOR.
    
    METHOD PRIVATE VOID genshell():  /*OS windows*/
        bhcim = {&batname} + GUID + ".bat".
        bexecp = {&batname} + GUID + ".p".
        OUTPUT TO VALUE(bhcim).
        PUT UNFORMATTED "@echo off" SKIP.
        PUT UNFORMATTED "set dlc={&OEDLC}" SKIP.
        PUT UNFORMATTED "set path=%path%;%dlc%\bin;" SKIP.
        PUT UNFORMATTED "if not exist {&OETMP} md {&OETMP}" SKIP.
        PUT UNFORMATTED "start /wait %dlc%\bin\prowin32.exe -pf {&pfpath} -p " + bexecp SKIP.    /*若是64bit OE 则为prowin.exe*/
        PUT UNFORMATTED "del /q /s " + bexecp SKIP.  /*删除p文件*/
        PUT UNFORMATTED "attrib -h -s -r -a %0" SKIP.
        PUT UNFORMATTED "del %0" SKIP.  /*bat文件删除自身*/
        PUT UNFORMATTED "exit" SKIP.
        OUTPUT CLOSE.

        ASSIGN datalog = {&temppath} + GUID + "cim".
        ASSIGN errlog = datalog + ".err".
        OUTPUT TO VALUE(bexecp).
        PUT UNFORMATTED "INPUT FROM " + datalog + "." SKIP.
        PUT UNFORMATTED "OUTPUT TO " + errlog + "." SKIP.
        PUT UNFORMATTED "PAUSE 0 BEFORE-HIDE." SKIP.
        PUT UNFORMATTED "RUN mf.p." SKIP.
        PUT UNFORMATTED "INPUT CLOSE." SKIP.
        PUT UNFORMATTED "OUTPUT CLOSE." SKIP.
        /*dynamic generate progress script to excute*/
        OUTPUT CLOSE.
    END METHOD.
    
    METHOD PRIVATE VOID osexec():
        IF SEARCH(bhcim) NE ? AND SEARCH(bexecp) NE ? THEN
        DO:
            IF synex THEN DO:    /*正常是同步执行 要等待*/
                OS-COMMAND SILENT VALUE(bhcim).
                /*OS-DELETE VALUE(bhcim).
                OS-DELETE VALUE(bexecp).    batch文件里自带删除*/
                IF NOT testmode THEN DO:
                    OS-DELETE VALUE(errlog).
                    OS-DELETE VALUE(datalog).  /*删除文件*/
                END.
            END.
            ELSE OS-COMMAND NO-WAIT VALUE(bhcim).  /*异步 不等待*/    /*产生的日志文件可另外设个脚本定时清理*/
        END.
    END METHOD.
    
    METHOD PUBLIC VOID batchload(INPUT dstring AS CHARACTER,INPUT execname AS CHARACTER):  /*dstring是character 有32k大小限制  longchar则没有*/
        DEFINE VARIABLE loadstring AS CHARACTER NO-UNDO.
        genshell().
        /*mutidm 
        mutidm EQ NO 单域
        mutidm EQ YES 多域
        */
        OUTPUT TO VALUE(datalog).
        ASSIGN loadstring = QUOTER({&username}) + ‘ ‘ + QUOTER({&userpsw}).
        IF mutidm THEN 
        loadstring = loadstring {&SK} domain. /*多域*/
        loadstring = loadstring {&SK} execname.
        IF dstring NE ‘‘ AND dstring NE ? THEN 
        loadstring = loadstring {&SK} dstring.
        loadstring = loadstring {&SK} ".".
        loadstring = loadstring {&SK} "YES".
        PUT UNFORMATTED loadstring.
        OUTPUT CLOSE.
        osexec().
    END METHOD.
    
    METHOD PUBLIC VOID lbatchload(INPUT dstring AS LONGCHAR,INPUT execname AS CHARACTER):  /*dstring是character 有32k大小限制  longchar则没有*/
        DEFINE VARIABLE loadstring AS LONGCHAR NO-UNDO.
        genshell().
        /*mutidm 
        mutidm EQ NO 单域
        mutidm EQ YES 多域
        */
        ASSIGN loadstring = QUOTER({&username}) + ‘ ‘ + QUOTER({&userpsw}).
        IF mutidm THEN 
        loadstring = loadstring {&SK} domain. /*多域*/
        loadstring = loadstring {&SK} execname.
        IF dstring NE ‘‘ AND dstring NE ? THEN 
        loadstring = loadstring {&SK} dstring.
        loadstring = loadstring {&SK} ".".
        loadstring = loadstring {&SK} "YES".
        COPY-LOB FROM loadstring TO FILE datalog NO-CONVERT.
        osexec().
    END METHOD.    /*10.1A 版本还没有重载...所以另写方法名*/

END CLASS.

2.例子

 define variable b as batchcim no-undo.
 define variable s as character no-undo.
 assign s = "cn200" + chr(10) + ".".
 b = new batchcim("us100").
 s:testmode = yes.
 b:batchload(s,"mgdomchg.p").
 delete object b.
 b = ?.

 

QAD 外部调用batch cimload类

标签:close   path   exe   例子   产生   cte   gic   程序   大小   

原文地址:https://www.cnblogs.com/skyofchaos/p/13776744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!