Skip to main content

Problem:

In the course of Cobol program execution, it would be desirable to issue a command to the Unix shell for processing and to work with the command's output.  Is it possible.

Resolution:

The procedure division statement is:

CALL 'SYSTEM' USING MY-COMMAND.

where MY-COMMAND is:

  01  MY-COMMAND.

        10  MY-COMMAND-LINE       PIC   X(2048).

        10  FILLER                             PIC  X   VALUE LOW-VALUES.

MY-COMMAND-LINE may contain any valid system command line, e.g. ls -l > lsout.txt

It is recommended that command output be redirected to a file if the Cobol program needs access to the results.

The special register RETURN-CODE is set, but the return code is the value returned form the "SYSTEM" function call and not the return code from the actual command executed.  Therefore the value of RETURN-CODE only indicates the success or failure of the "SYSTEM" function call and not the outcome of the commandline passed to the function.

Old KB# 7194