Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange issue calling script from COBOL program

Status
Not open for further replies.

jewilson2

Technical User
Feb 7, 2002
71
US
I have a COBOL program that reads a DB and strings together a pipe (|) delimited flat file. Once the file creation is complete, it calls a section to invoke a shell script to move the file from one server to another.

Something about the pipe delimiter causes the function to fail. Things to remember.
1. The shell script works great standalone if i invoke it manually after the cobol program runs. So I know the shell script is right.
2. The COBOL program will invoke the shell script IF I change the delimiter to something other than a pipe (|). So I know the commands are right.

I guess my question is, what about a pipe would blow up the CALL "SYSTEM" USING WS-COMMAND function?

PD Code:

Code:
           MOVE SPACES                 TO WS-BCX-SEGMENT.

          STRING  WS-DELIM             DELIMITED BY SIZE
006000            ITL-LOCATION         DELIMITED BY WS-SPACE1
                  WS-DELIM             DELIMITED BY SIZE
                  ITL-LOCATION         DELIMITED BY WS-SPACE1
                  WS-DELIM             DELIMITED BY SIZE
                  ICL-NAME             DELIMITED BY WS-SPACE2
                  WS-DELIM             DELIMITED BY SIZE
                  ITL-ITEM             DELIMITED BY WS-SPACE1
                  WS-DELIM             DELIMITED BY SIZE
                  WS-DELIM             DELIMITED BY SIZE
                  ITE-DESCRIPTION      DELIMITED BY WS-SPACE2
                  WS-DELIM             DELIMITED BY SIZE
                  ITE-DESCRIPTION2     DELIMITED BY WS-SPACE2
                  WS-DELIM             DELIMITED BY SIZE
                  WS-DELIM             DELIMITED BY SIZE
                  WS-DELIM             DELIMITED BY SIZE
                  WS-DELIM             DELIMITED BY SIZE
                  WS-DELIM             DELIMITED BY SIZE
                  WS-REORDER-POINT     DELIMITED BY SIZE
                  WS-DELIM             DELIMITED BY SIZE
                  WS-REORDER-POINT     DELIMITED BY SIZE
                  WS-DELIM             DELIMITED BY SIZE
                  ITL-UOM              DELIMITED BY WS-SPACE1
.
.
.
             INTO WS-BCX-SEGMENT.

           WRITE BCX-REC              FROM WS-BCX-SEGMENT.

******************************************************************
       3500-RUN-SCRIPT                 SECTION.
      ******************************************************************
     MOVE SPACES                     TO  WS-SYS-COMMAND.
            STRING "/bin/ksh " """"             DELIMITED BY SIZE
               "/"                              DELIMITED BY SIZE
               WS-LAWDIR-LC                     DELIMITED BY SPACES
               "/"                              DELIMITED BY SIZE
               WS-PROD-LINE-LC                  DELIMITED BY SPACES
               "/script/FtpWrap.sh"             DELIMITED BY SIZE
               " "                              DELIMITED BY SIZE
               WS-PROD-LINE-LC                  DELIMITED BY SPACES
               " "                              DELIMITED BY SIZE
               WS-XMIT-FILE                     DELIMITED BY SPACES
               " 2>/dev/null" """"              DELIMITED BY SIZE
                                                INTO WS-SYS-COMMAND.
            DISPLAY WS-SYS-COMMAND.
            CALL "SYSTEM" USING WS-SYS-COMMAND.

The code above basically strings together a file, then strings together a command to invoke the shell script that ftp's that file. I have all of the WS set correctly to build this file. The error I get when this runs is below. You can see the command that the last section strings together. If I type this command in manually from a commandline, the script ftp's the file as it should. If I change the delimiter, it works from the COBOL program.

Processing ZZ660 - BCX ITEM DETAIL EXTRACT
/bin/ksh "/lawson/lawtest/apps/crp/script/FtpWrap.sh crp BCXITDT
sh: 0403-057 Syntax error at line 1 : `|' is not expected.
 
As you are calling a Unix shell, the pipe is used by the shell for other things.
You need to parse the command line and "escape" the reserved characters e.g. "\|" will pass the pipe as a char, not as "command"

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Thanks for the reply.
Tried that yesterday. It does allow the script to work, but it changes my delimiter to "\|" instead of "|"....which won't work for this file.

What I don't get is that the pipe is in no way, shape, or form part of the command that invokes the script.
/bin/ksh "/lawson/lawtest/apps/crp/script/FtpWrap.sh crp BCXITDTL 2>/dev/null"
The only place that a pipe lives is in the file that is to be ftp'd.

I'm bumfuzzled.
 
Try to replace this:
/bin/ksh "/lawson/lawtest/apps/crp/script/FtpWrap.sh crp BCXITDTL 2>/dev/null"
By this:
/bin/ksh /lawson/lawtest/apps/crp/script/FtpWrap.sh crp BCXITDTL 2>/dev/null

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I tried it without the quotes too...no go.

Finally figured it out. It was because I wasn't terminating my WS-SYS-COMMAND call completely.

I changed the PD section to look like this:

Code:
MOVE SPACES                     TO  WS-SYS-COMMAND.
            STRING "/bin/ksh " """"             DELIMITED BY SIZE
               "/"                              DELIMITED BY SIZE
               WS-LAWDIR-LC                     DELIMITED BY SPACES
               "/"                              DELIMITED BY SIZE
               WS-PROD-LINE-LC                  DELIMITED BY SPACES
               "/script/BCXITDTL.sh"            DELIMITED BY SIZE
               " "                              DELIMITED BY SIZE
               WS-PROD-LINE-LC                  DELIMITED BY SPACES
               " "                              DELIMITED BY SIZE
               WS-XMIT-FILE                     DELIMITED BY SPACES
               " 2>/dev/null" """"              DELIMITED BY SIZE
                                                INTO WS-SYS-COMMAND.
            DISPLAY WS-SYS-COMMAND.
            CALL "SYSTEM" USING WS-SYS-LINKAGE.

And changed the WS to this:

Code:
02  WS-SYS-LINKAGE.
               03  WS-SYS-COMMAND        PIC X(150) VALUE SPACES.
               03  WS-END-CMD            PIC X(01)  VALUE X"00".

So rather than calling SYSTEM with WS-SYS-COMMAND, I call it using the WS-SYS-LINKAGE.

Thanks for the help.
JW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top