z/OS Using REXX and z/OS UNIX System Services
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Run a shell command and read its output into a stem

z/OS Using REXX and z/OS UNIX System Services
SA23-2283-00

This REXX program runs the ls shell command and reads the output from the command into a stem. The program uses pipe, close, and EXECIO. It accesses /dev/fdn, where n is a number that the exec concatenates to /dev/fd.
Note: You can use this example to trap output from commands when the output is relatively small (less than 100KB). For command output that could be larger, you should use the spawn service.
/* rexx */
address syscall 'pipe p.'                    /* make a pipe           */
'ls>/dev/fd' || p.2                          /* run the ls command and
                                                redirect output to the
                                                write end of the pipe */
address syscall 'close' p.2                  /* close output side     */
address mvs 'execio * diskr' p.1 '(stem s.'  /* read data in pipe     */
do i=1 to s.0                                /* process the data      */
   say s.i
end

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014