Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/examples/demo/pipes2.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH pipes and files demonstration program
\ Copyright 2002,2008 J.L. Bezemer

file ls                                \ handle for 'ls'
file 4tH                               \ handle for the 4tH files
file dump                              \ handle for the output file
                                       \ open a pipe to 'ls'
s" ls *.4th" input pipe + open error? abort" Can't open pipe" to ls
                                       \ open the output file
s" doubleoutput.txt" output open error? abort" Can't open output" to dump
dump use                               \ use the output file for output

begin
  ls use                               \ use the pipe for input
  refill                               \ read the 4tH file name
while                                  \ write its name to the output file
  0 parse over over ." >>>" type cr
  input open error? abort" Can't open file" to 4tH

  4tH use                              \ now use the 4tH file for input
  begin
    refill                             \ read a line of the 4tH file
  while
    0 parse type cr                    \ write it to the output file
  repeat
  4tH close                            \ all read, now close the 4tH file

repeat                                 \ read the next 4tH filename

ls   close                             \ all files done, now close the pipe
dump close                             \ and the output file
                                       \ note that all standard channels are
." *** DONE ***" cr                    \ restored, so this appears on screen




Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.