Posted to tcl by msiism at Wed Jan 27 13:05:38 GMT 2021view raw

  1. #!/usr/bin/env tclsh
  2.  
  3. set find_done 0
  4. set find_path $env(HOME)
  5.  
  6. proc _pipe_chunk {ichan} {
  7.  
  8. global find_done
  9. set chunk {}
  10.  
  11. # Read a single character from $ichan.
  12. # See whether it's NUL.
  13. # If not, append it to $chunk.
  14. # Return $chunk when it's complete (NUL encountered).
  15. # Handle occurrence of EOF while doing this.
  16.  
  17. while {true} {
  18. set char [read $ichan 1]
  19. if {[eof $ichan]} {
  20. close $ichan
  21. set find_done 1
  22. break
  23. } elseif {$char == "\0"} {
  24. puts $chunk
  25. break
  26. } else {
  27. set chunk ${chunk}${char}
  28. }
  29. }
  30. }
  31.  
  32. set find_out [open "| find $find_path -type f -print0" r]
  33. chan event $find_out readable [list _pipe_chunk $find_out]
  34. #chan configure $find_out -buffering line
  35.  
  36. vwait $find_done

Comments

Posted by msiism at Wed Jan 27 13:36:26 GMT 2021 [text] [code]

s/vwait $find_done/vwait find_done