Search code examples
ibm-midrangecobolqshell

Read back output from command using QCMDEXC in COBOL iSeries AS/400


I am using QCMDEXC in COBOL to execute a QShell command like this:

   01 PROGRAM-VARIABLES.                        
      05 CL-CMD PIC X(33)                       
                VALUE "STRQSH CMD('LS')".
      05 PACK-VAL PIC 9(10)V9(5) COMP-3         
                  VALUE 16.                                    
   MAINLINE.                                    
       CALL "QCMDEXC" USING CL-CMD PACK-VAL.  

The LS is being executed and the result is shown in the screen. However, I cannot find anywhere or come up with a way of reading that out put, in this case a list of files/folders from "unix" into COBOL again. (I verified the command is correctly launched by COBOL, because if I change it by STRQSH CMD('LS>fromcobol.txt'), the file 'fromcobol.txt' is created with the correct output, but I don't know how to retrieve that output into the same COBOL program... I am very ignorant of COBOL, I started learning today and it took me very long just to launch the command...)

Thanks a lot for any help...


Solution

  • There's a thread in the archives of the midrange.com COBOL400 mailing list about reading IFS files in COBOL. Here's a post from that thread with a sample program. https://archive.midrange.com/cobol400-l/200010/msg00006.html