Posted to tcl by mpcjanssen at Wed Jul 31 12:57:05 GMT 2019view raw

  1. proc test {args} {puts $args ; return "initialize watch finalize read write"}
  2.  
  3. proc nexec {cmd in out stderr} {
  4. lassign [chan pipe] in1 out1
  5. lassign [chan pipe] in2 out2
  6. lassign [chan pipe] in3 out3
  7. puts [exec {*}$cmd >@ $out2 2>@ $out3 <@ $in1 &]
  8. fileevent $in2 readable [list chan copy $in2 $out]
  9. fileevent $in3 readable [list chan copy $in3 $stderr]
  10. fileevent $out1 writable [list chan copy $in $out1]
  11. }
  12.  
  13. proc test {args} {
  14. puts $args
  15. set rest [lassign $args mode chan]
  16. switch -exact $mode {
  17. read {puts $chan "Test" ; close $chan}
  18. initialize {return "initialize watch finalize read write"}
  19. finalize {}
  20. }
  21. }
  22.  
  23. set c [chan create "read write" test]
  24.  
  25. nexec {sh -c "echo test"} $c $c $c
  26.  
  27. vwait forever
  28.