IBM Support

Using a Windows Batch File to Create a Connect:Direct Process

Technical Blog Post


Abstract

Using a Windows Batch File to Create a Connect:Direct Process

Body

The question sometimes arises “Can I create and run a Connect:Direct process from a batch file?”

Yes you can.

The first thing you need to do is to create a process, either using the Requester, CDBrowser User Interface or a text editor.  For purposes of this article I used the Requester.  I started with the process below.  This gives an easy starting point to create a process using a batch file since the Requester has already checked the syntax.

/*BEGIN_REQUESTER_COMMENTS

    $PNODE$="CDNODE.CD460" $PNODE_OS$="Windows"

    $SNODE$="CDNODE.CD460" $SNODE_OS$="Windows"

    $OPTIONS$="WDOS"

  END_REQUESTER_COMMENTS*/

 

SAMPLE PROCESS

      SNODE=CDNODE.CD460

 

STEP1 COPY

      FROM (

            FILE="C:\Program Files (x86)\Sterling Commerce\Connect Direct v4.6.00\Server\Process\Sample.html"

      )

      TO (

            FILE="C:\Program Files (x86)\Sterling Commerce\Connect Direct v4.6.00\Server\Process\Verify.html"

            DISP=RPL

      )

 

PEND

 

The next step is to copy the file into a text editor, I used Notepad.  Edit the file to look like this:

echo off

if "%1"== "" goto mysyntax else goto mysyntax2

:mysyntax2

if "%2"== "" goto mysyntax else goto mysyntax3

:mysyntax3

if "%3"== "" goto mysyntax

echo off

echo submit > myproc.txt

 

echo SAMPLE PROCESS >> myproc.txt

echo    SNODE=%1 >>myproc.txt

 

echo STEP1 COPY >>myproc.txt

echo    FROM ( >>myproc.txt

echo                FILE=%2 >>myproc.txt

echo    ) >>myproc.txt

echo    TO ( >>myproc.txt

echo                FILE=%3 >>myproc.txt

echo                DISP=RPL >>myproc.txt

echo    ) >>myproc.txt

 

echo PEND; >>myproc.txt

 

direct -fcddef.bin < myproc.txt > myproc.log

goto END

:mysyntax

cls

echo off

echo ======================================================

echo The syntax for this command is

echo onTheFly ^<snode name^> ^<source file^> ^<destination file^>

echo ======================================================

 

:END

 

Save the edited file as a .bat or .cmd file.  I named this file onTheFly.cmd.

 

The batch file onTheFly echoes the Connect:Direct commands into the file I called myproc.txt. This is the file that will serve as the input to Connect:Direct’s  Command Line Interface (CLI).  In this example onThrFly requires three inputs.  It requires the snode name, the source file name and the destination file name.  As you can see this example does check the syntax and if three inputs are not provided it displays the required syntax.

 

This is the line that calls the CLI to submit the process:

direct -fcddef.bin < myproc.txt > myproc.log

For simplicity I created this batch file in Connect:Direct’s Common Utilities directory to avoid the necessity of fully qualifying the path to the direct command.  I also used only file names for source and destination allowing for the use of the default upload and download directories defined in Connect:Direct.  Direct is the command that opens the CLI, in this case I am using the cddef.bin file to provide the connection information to attach to the Connect:Direct node acting as the pnode for the process.  This file is produced by the lcu.bat file in the Connect:Direct Common Utilities directory.  The advantage of using the cddef.bin rather than relying on the direct command without any parameters is that it is not dependent on the user logged into Windows. 

NOTE: See the section Using the LCU at the end of this article for more explanation on the LCU and the CDDEF.bin.

 

 

The file myproc.txt is created by onTheFly and contains the commands provided to Connect:Direct.  The contents from this example are:

submit

SAMPLE PROCESS

SNODE=CDNODE.CD460

STEP1 COPY

FROM (

        FILE=testfile.in

)

TO (

        FILE=testfile.out

        DISP=RPL

)

PEND;

 

I also added an output log to the example, myproc.log.  This log will let you know whether or not the process submission was successful.  The contents for this example were:

 

Connect:Direct Command Line Interface

Version 4.6.0.5_iFix010

(C) Copyright IBM Corp. 1983, 2012 All Rights Reserved.

*************************************************

Successfully connected to CDNODE.CD460

> ===========================================================================

 

                                     Submit

=============================================================================

NAME     NUMBER    USER             SUBMITTER NODE   QUEUE  STATUS

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

SAMPLE   63        cdadmin          CDNODE.CD460     EXEC   PE

> Successfully disconnected from CDNODE.CD460

 

As you can see from the log the CLI successfully connected to the node CDNODE.CD460, submitted a process named SAMPLE with a process number of 63 then successfully disconnected from the node.  All of the statistics records for the process can be viewed in the Requester.

 

 

 

 

Using the LCU

When using the direct.exe command to access the CLI there a couple of options that you can use.  The first is to use direct with no arguments/options.  Using this option you just type direct <enter> at the command prompt after changing directories to the …\Connect Direct v4.x.x\Common Utilities directory.  This is the same as using the Start Menu and going to Start>All Programs>IBM Sterling Connect Direct v4.x.x>CD Command Line Interface.  Both of these methods rely on the Client Connection Utility (CCU) being configured.  The CCU configuration is stored in Windows Registry, the problem with using CCU defaults is that the configuration is in the Current User section of the Registry rather than the Local Machine.  This makes it dependent on the user logged into Windows.  If you are using a third party scheduler to kick off the batch files this can be problematic since the userid used by the scheduler might not have the CCU configured.

 

Another method, closely related to the first, is to use switches after the direct command.  This would look similar this:

direct –nMyNode.cd –ucduser –pcduserpwd

The shortcomings here are that the node has to be setup in the CCU, though the user does not have to be, and the obvious one…the password is in clear text either on the command line or the batch file using it.

 

The third option is to use the –f option for direct to take login credentials from a file.  The command in this case looks similar to:

direct –fcddef.bin

 

The file cddef.bin is the default output from the lcu.bat file in your Common Utilites directory.  You create the cddef.bin by executing the lcu.bat and completing the input.

>lcu

   ********************************************************************

   *                 Java Client Connection Utility                   *

   * IBM(R) Sterling Connect:Direct(R) for Microsoft Windows v4.6.0.5 *

   *------------------------------------------------------------------*

   * Licensed Materials - Property of IBM                             *

   * (C) Copyright IBM Corp. 1983, 2014 All Rights Reserved.          *

   * US Government Users Restricted Rights - Use, duplication         *

   * or disclosure restricted by GSA ADP Schedule Contract            *

   * with IBM Corp.                                                   *

   ********************************************************************

Note: you are currently running in compatible mode using standard

security (version 2). To save the configuration information using

strong password security (version 3), specify -v3 on the command

line. See 'lcu -h' for additional information.

 

Node:          <Enter> = 'MyNode.cd'

API Address:   <Enter> = '123.123.123.123'

API Port:      <Enter> = '1363'

User Name:     <Enter> = 'cduser'

Password:

 Confirm Password:

 

The default file name for the output is cddef.bin, you can specify a file name by using the –f option.

lcu –fMyCdDef.bin

 

To enter the CLI using this file you again use the –f option and enter:

direct –fMyCdDef.bin

 

The two major advantages for using this method are:

  1. It uses a file on the file system available to all users rather than a user specific Registry entry.
  2. LCU.bat is a java program that encrypts the password.

 

 

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SS4PJT","label":"IBM Sterling Connect:Direct"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11123965