Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for tee.rex

(view source code of tee.rex as plain text)

  1. /* TEE port */
  2.  
  3. /* Parse and check command line arguments */
  4. Parse Upper Arg ."/D:"maxwait .
  5. If maxwait = "" Then Do
  6. 	Parse Arg outfile dummy
  7. 	maxwait = 1
  8. End
  9. Else Do
  10. 	Parse Arg .":"maxwait outfile dummy
  11. End
  12. If outfile = "" Then Call Syntax
  13. If dummy  <> "" Then Call Syntax
  14. If maxwait = "" Then Call Syntax
  15. If DataType( maxwait, "W" ) = 0 Then Call Syntax
  16. If maxwait <  1 Then Call Syntax
  17.  
  18. /* Initialize variables */
  19. stopflag = 0
  20. counter  = 0
  21.  
  22. /* Initialize RexxUtil */
  23. If RxFuncQuery( "SysLoadFuncs" ) <> 0 Then Do
  24. 	Call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  25. End
  26. Call SysLoadFuncs
  27.  
  28. /* Read, display and redirect standard input */
  29. Do Until stopflag = 1
  30. 	If lines( STDIN ) = 0 Then Do
  31. 		counter = counter + 1
  32. 		If counter > maxwait Then stopflag = 1
  33. 		Call SysSleep 1
  34. 	End
  35. 	Else Do
  36. 		Parse Pull line
  37. 		Say line
  38. 		Call LineOut outfile, line
  39. 	End
  40. End
  41.  
  42. /* Normal program termination */
  43. Exit 0
  44.  
  45.  
  46. Syntax:
  47. 	Say
  48. 	Say "Tee.rex,  Version 1.00 for (Regina) Rexx"
  49. 	Say "Port of Unix' TEE command"
  50. 	Say "Redirects its input to the console and to a file simultaneously"
  51. 	Say
  52. 	Say "Usage:  any_command  |  <REXX>  TEE.REX  [/D:nn]  output_file"
  53. 	Say
  54. 	Say 'Where:  "any_command" is the command whose output you want to redirect'
  55. 	Say '        "output_file" is the file where any_command'||"'s output is redirected to"
  56. 	Say '        "nn"          is the max idle time (in seconds) allowed for any_command'
  57. 	Say '        "<REXX>"      is your Rexx interpreter:'
  58. 	Say "                    - Windows:  REGINA.EXE with RexxUtil"
  59. 	Say "                    - OS/2:     no need to specify, just rename script to *.cmd"
  60. 	Say
  61. 	Say "Written by Rob van der Woude"
  62. 	Say "http://www.robvanderwoude.com"
  63. 	Say
  64. 	Exit 1
  65. Return
  66.  

page last uploaded: 2017-08-21, 14:26