AppWorx, Dollar Universe and Sysload Community

Expand all | Collapse all

Uproc to run a Windows bat file

  • 1.  Uproc to run a Windows bat file

    Posted Oct 17, 2018 04:59 PM

    Hello,

     

    We would like to create a uproc on a Windows DUAS and run a bat file.  How can we do this?

     

    Thanks in advance for your help.



  • 2.  Re: Uproc to run a Windows bat file

    Posted Oct 18, 2018 11:43 AM

    I hope someone can please assist.  We do not know how to set up a uproc to run a windows bat file.  

    We tested by creating a uproc type CMD, and the Variables as, Command C:\ORSYP\GM2.BAT, and Path C:\Windows\System32.  When we ran it, we get an error in the job log, "IMPOSSIBLE TO RETRIEVE COMMAND SCRIPT - JOB ABORTED".



  • 3.  Re: Uproc to run a Windows bat file

    Broadcom Employee
    Posted Oct 19, 2018 12:45 AM

    Hello GerryMuyargas611489,

     

    You can try to use Uproc type CL_EXT (external script) to run bat scritp.

    For example:

    Refer Docs: Automic 

     

    Hope this helps,

    Hoai



  • 4.  Re: Uproc to run a Windows bat file

    Posted Oct 19, 2018 01:44 AM

    Thank you Hoai.  I tried doing this, ran my uproc, and although an output was produced from my bat file, the uproc Aborted.   See History trace below.

    --------------------------------------------------

    20181019013316 Start Condition Check
    Processing Date 20181019
    20181019013316 Submitted in BATCH Q: SYS_BATCH
    under ENTRY N° : 000027

    20181019013317 BATCH starting
    20181019013350 BATCH ending
    Job aborted or killed during execution

    20181019013350 *** TASK ENDED ABNORMALLY ***
    10/19/2018 01:33:50 NOTIFICATION_EMAIL REQUEST OK - Aborted
    gmuyargas@rexall.ca;
    *** Uproc ABORTED, Completion Instructions were not executed ***

    -----------------------------------------------------



  • 5.  Re: Uproc to run a Windows bat file

    Broadcom Employee
    Posted Oct 19, 2018 11:25 AM

    Hello Gerry, you should take a look at the script and job log as it looks like it does not exist with a proper return code.



  • 6.  Re: Uproc to run a Windows bat file

    Posted Nov 01, 2018 12:18 PM

    One of the ways to do this is as mentioned a CL type Uproc (one where you can so some coding)

     

    In the Uproc you need to capture the return code from the script. Try this

     

    • Make a simple .bat file  something like <path to .bat>\test_script.bat
    • The script could something like a simple echo as below 

             test_script.bat

                @echo off      

                echo This is a test message

     

    •      In the Uproc (call it test_uproc1) call the script (in quotes to allow for spaces) as you would in dos and add the capture code at the end so that the Uproc exits with the errorlevel of the script

     

                  test_uproc1

                @echo off 

                "<path to .bat>\test_script.bat"

                      echo errorlevel from script is set to %errorlevel%

                set resexe=%errorlevel%

     

    When the Uproc runs it will run the script then all being well it exit with the same code as the script, Script name can be passed as a variable to the Uproc but try the test first. 



  • 7.  Re: Uproc to run a Windows bat file

    Posted Nov 08, 2018 11:44 AM

    Thanks for your reply Angus.  Sorry for the late reply, but not sure if I did my test correctly, but my joblog shows below.  Do I have to add all the lines above in the CL_EXT parameters of my test uproc? Or somewhere else?

     

    @echo off "c:\orsyp\test_script" echo errorlevel from script is set to %errorlevel% set resexe=%errorlevel%

     

    -----------------------------

    C00-SUPPORT-SITE DEBUT
    C00-SUPPORT-SITE WSPGM-CODNOEUD CatMgmtBatDev
    _!================================================
    _!**
    $!** PROCEDURE .. : TEST_UPROC1
    $!** VERSION .....: 000
    $!** EXECUTION .. : 0000006
    _!**
    _!** PROCESS DATE : 11/08/2018
    _!**
    _!------------------------------------------------
    $!** PARAMETERS. : None
    _!------------------------------------------------
    _!** VARIABLES
    _!------------------------------------------------
    $!** INHERITANCE VARIABLES
    _!================================================
    Error: Cannot create temporary job script.
    Uproc script @echo off c\\orsyp\test_script echo errorlevel from script is set to 0 set resexe=0 not accessible.

    ------------------------------------------------



  • 8.  Re: Uproc to run a Windows bat file

    Posted Nov 08, 2018 12:20 PM

    Try this make a test script with the content below and save to a location like c:\tmp\test.bat. Script content below

     

    @echo off

    echo This is a test script

    set errorlevel=0

    echo Message from the script - errorlevel in script is set to %errorlevel%
    set resexe=%errorlevel%

     

    This will exit with the errorlevel set in the script (which is 0)

     

    Now make a test Uproc to run the script, call is something like TEST_PROC1. make it type CL_INT. when you edit it add in the code below to call the script you just made.

     

    @echo off

    echo "This is a message from the Uproc"

    REM ###  Now running script  ###

    call c:\tmp\test.bat

    echo Message from the Uproc - errorlevel from the script just run is %errorlevel%

    set resexe=%errorlevel%

     

    Run the Uproc using a suitable submission account, hopefully the result will be as below.

     

    $!** PROCEDURE .. : TEST_UPROC1
    $!** VERSION .....: 000
    $!** EXECUTION .. : 0001270
    _!**
    _!** PROCESS DATE : 08/11/2018
    _!**
    _!------------------------------------------------
    $!** PARAMETERS. : None
    _!------------------------------------------------
    _!**  VARIABLES
    _!------------------------------------------------
    $!**  INHERITANCE VARIABLES
    _!================================================
    "This is a message from the Uproc"
    This is a test script
    Message from the script - errorlevel in script is set to 0
    Message from the Uproc - errorlevel from the script just run is 0



  • 9.  Re: Uproc to run a Windows bat file

    Posted Nov 08, 2018 02:52 PM

    Thank you, that test worked!  I have a concern though when running a batch script using CL_EXT.  When we used CMD type it does not run the batch script.  But when we use CL_EXT, it runs oka, however, the uproc goes into Abotrted starte, and doesn't show anything in the joblog.  What do I do?  



  • 10.  Re: Uproc to run a Windows bat file

    Posted Nov 09, 2018 05:46 AM

    There is a description on the Reference manual about the types of Uproc CMD, CL_EXT and CL_INT.  Generally CMD is used to carry out simple system commands like cp -p file1 file2.  CL_EXT is used to run scripts external to $U (though the script should reside on the node). CL_INT is used to create a kind of wrapper script that lives in the Uproc definition in $U.

     

    Using CL_INT you can add some manipulation or $U functions before running your actual script. This could be a message, working out a date, checking the name of a file before running your script. Provides lots of flexibility plus in higher $U versions there are other shells available such as POWERSHELL.

     

    (You didn't mention the version of $U you are running and the OS in the original query).

     

    Hope this helps



  • 11.  Re: Uproc to run a Windows bat file

    Posted Nov 09, 2018 07:26 AM

    Thanks again!   We are at 6.9.21.



  • 12.  Re: Uproc to run a Windows bat file

    Posted Nov 09, 2018 07:39 AM

    One last thing since version 5.3 the default exit code from a Uproc is 1 so unless you do something in a uproc to make the return code 0 it will be marked a aborted.

     

    Something as simple as capturing the return code from your successful script then exit with that.

     

    This avoids false positives as you know your code or script has worked successfully.