home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / rxsnoop.zip / readpipe.cmd next >
OS/2 REXX Batch file  |  1994-07-02  |  2KB  |  67 lines

  1. /* REXX * Read a named pipe as provided by Binkley or Maximus */
  2.  
  3. /*
  4.            Dennis Peterson *
  5.         OS/2 Northwest BBS *
  6.                1:343/179.0 *
  7.               Bellevue, WA *
  8.             (206) 562-7212 *
  9.              June 28, 1994 *
  10.    With much borrowed code *
  11. */
  12.  
  13. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  14. call SysLoadFuncs
  15.  
  16. Signal on HALT name cleanup
  17.  
  18. /* 
  19.    Usage: readpipe pipename mode
  20.    pipe name example: \pipe\bink1 
  21.    modes are binkley and maximus
  22.    default is binkley
  23. */
  24.  
  25. parse arg pipe_name pipe_type
  26. if pipe_type = "" then pipe_type = "binkley"
  27.  
  28. parse value stream(pipe_name, 'C', 'OPEN READ') with PipeState ':' OS2RC
  29. if OS2RC = 231 then call SysWaitNamedPipe pipe_name, -1
  30.  
  31. call SysCls
  32.  
  33. do forever
  34.    pipe_state = SysWaitNamedPipe(pipe_name, 2)
  35.    select
  36.  
  37.       when pipe_state = 0 then do
  38.          parse value stream(pipe_name, 'C', 'OPEN READ') with PipeState ':' OS2RC
  39.          if OS2RC = 231 then call SysWaitNamedPipe pipe_name, -1
  40.       end
  41.  
  42.       when pipe_state = 3 then do
  43.          say "waiting for a pipe connection"
  44.          do while pipe_state = 3
  45.             pipe_state = SysWaitNamedPipe(pipe_name, 2)
  46.             call syssleep 1
  47.          end
  48.          say
  49.       end
  50.  
  51.       when pipe_state = 121 then do
  52.          if pipe_type = "binkley" then
  53.             current_line = charin(pipe_name,, 80)
  54.          else
  55.             current_line = linein(pipe_name)
  56.          if current_line <> "" then say current_line
  57.       end
  58.  
  59.       otherwise do
  60.          call syssleep 1
  61.       end
  62.    end
  63. end
  64.  
  65. cleanup:
  66. exit
  67.