Getting a response from a command line program

I am trying to find the best way to call a command line .exe and get a response back. I tried C$SYSTEM but all I can get back is the called program's exit status. Any ideas?

Thanks, Steve

Parents
  • Verified Answer

    You can access a process using COBOL file I/O verbs, by defining it as a file using -P in the ASSIGN clause of the SELECT. Then you can read the output of the command using OPEN INPUT and READ verbs.

           select my-command assign to "-P ls -l /path/to/somedir"
               organization is line sequential
               file status is my-command-stat.
    
           FD my-command.
           01 output-line pic x(80).
    
           01 my-command-stat   pic x(02).
               88 my-command-eof value "10".
    
           ...
               open input my-command
               perform until my-command-eof
                   read my-command next record
                   ...etc...
           ...
    

    You can also write to an external command, using OPEN OUTPUT and WRITE. You cannot use OPEN EXTEND or OPEN I-O.

    This example assumes a Unix or Linux environment, but you can do this on Windows as well - but with some additional handling. Read the docs for detail: ACUCOBOL-GT User's Guide, Section 2.9.1

Reply
  • Verified Answer

    You can access a process using COBOL file I/O verbs, by defining it as a file using -P in the ASSIGN clause of the SELECT. Then you can read the output of the command using OPEN INPUT and READ verbs.

           select my-command assign to "-P ls -l /path/to/somedir"
               organization is line sequential
               file status is my-command-stat.
    
           FD my-command.
           01 output-line pic x(80).
    
           01 my-command-stat   pic x(02).
               88 my-command-eof value "10".
    
           ...
               open input my-command
               perform until my-command-eof
                   read my-command next record
                   ...etc...
           ...
    

    You can also write to an external command, using OPEN OUTPUT and WRITE. You cannot use OPEN EXTEND or OPEN I-O.

    This example assumes a Unix or Linux environment, but you can do this on Windows as well - but with some additional handling. Read the docs for detail: ACUCOBOL-GT User's Guide, Section 2.9.1

Children
No Data