Version 9 of pipe

Updated 2004-12-02 21:58:54

pipe ?fileId_var_r ?fileId_var_w

Create a pipe. If fileId_var_r and fileId_var_w are specified, then pipe will set the a variable named fileId_var_r to contain the fileId of the side of the pipe that was opened for reading, and fileId_var_w will contain the fileId of the side of the pipe that was opened for writing.

If the fileId variables are not specified, then a list containing the read and write fileIdw is returned as the result of the command.

There is a proposal tclx file commands for core [seems like something is missing here...]


[We also could talk about the abstract notion of "pipe", and how it comes up in conversation far more than just its use in reference to this command.]


Can somebody give an example for this? My attempt to use

 package require Tclx
 pipe rpipe wpipe;
 puts $wpipe "test\n";
 read $wpipe

simply leads to a lock up. Any help appreciated ;).

The problem is that read tries to read to the end of file. Since a pipe does not have and end of file indication ( unless one of the ends is closed) read never returns. If you use the following or used read with a specific capture size as seen in the 2nd example


#this seems to work package require Tclx pipe rpipe wpipe; puts $wpipe "test" flush $wpipe puts "gets $rpipe"


and so does this more elaborate version using read with a capture size of 1000 bytes the larger the capture size the less likely you will have to loop more than once. Also critical was using fconfigure to make it non-blocking.


fconfigure $rpipe -blocking 0 puts $wpipe "test" flush $wpipe set buff "" set done 0 while { !$done } {

    set appstr [ read $rpipe 1000 ]
    append buff $appstr
    if { [ string length $appstr ] != 1000 } {
        set done 1;
    } 

} puts "$buff"


Category Command for TclX package.