REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Pipes & Errorlevel



If you're using pipes in REXX programs, remember that the special REXX 
variable RC always contains the return code of the last program in the 
command containing the pipes. 
Example: 

 
/*                                                                    */
  address cmd 'dir | sort | find "<DIR>" '

                    /* The next statement will always print the       */
                    /* return code of the find command as the         */
                    /* value of RC                                    */
  say 'RC=' || rc



To read the return codes of the programs in the middle of the pipe as 
well, you can use a REXX wrapper. 
Example: 

 
/* ------------------------------------------------------------------ */
/* PushRC - simple wrapper program to save the return code of an      */
/*          OS/2 command or program in the current REXX queue         */
/*                                                                    */
/* Usage: pushRC program parameter                                    */
/*                                                                    */
/* History                                                            */
/*   01.09.1996 /bs v1.00                                             */
/*     - initial release                                              */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */

  parse arg progName progParameter

  "cmd /c" progName progParameter

                    /* progname (or something similar) is necessary   */
                    /* because OS/2 is a multi-tasking                */
                    /* operating system                               */
  push progName "RC="rc


Usage example: 

 
/*                                                                    */
  address cmd "pushrc dir | pushrc sort | pushrc find ""<DIR>"" "

  do while queued() <> 0
    say lineIn( "QUEUE:" )
  end /* do while queued() <> 0 */

(see also Using PIPEs) 
  

Inf-HTML End Run - Successful