Posted to tcl by hypnotoad at Wed Dec 11 20:03:50 GMT 2019view raw
- # Master.tcl
- set here [file dirname [file normalize [info script]]]
- puts "I AM $here"
-  
- lassign [chan pipe] slaveout pipein
-  
- puts "STARTING SLAVE"
- set slavein [open [list | [info nameofexecutable] [file join $here slave.tcl] ] r+]
- set slaveout $slavein
-  
- proc SEND {command} {
-   global slavein slaveout
-   puts "M> $command"
-   chan puts $slavein $command
-   #catch {chan flush $slavein}
-   gets $slaveout r
-   puts "M< $r"
-   return $r
- }
- chan configure $slaveout -buffering line
-  
- puts "SENDING COMMAND"
- SEND {expr 2+2}
- SEND {clock seconds}
-  
- after 2000
- SEND {expr 2+6}
- SEND {clock seconds}
- after 2000
- SEND {exit}
- exit 0
-  
- # slave.tcl
- set here [file dirname [file normalize [info script]]]
- set flog [open [file join $here log] w]
- chan configure $flog -buffering line
- puts $flog "STARTED"
- chan configure stdin -buffering line
- chan configure stdout -buffering line
-  
- while 1 {
-   try {
-     puts $flog "S WAIT"
-     if {[gets stdin line]<=0} {
-       exit 1
-     }
-     puts $flog "[clock seconds] S< $line"
-     set r [eval $line]
-     puts $flog "[clock seconds] S> $r"
-     puts stdout $r
-   } on error {er errdat} {
-     puts $flog [dict get $errdat -errorinfo]
-   }
- }
-  
-