Recently on comp.lang.tcl someone was trying to get the following code to work: proc gzip {buf} { set fd [open "|gzip -c" r+] fconfigure $fd -translation binary -encoding binary puts $fd $buf flush $fd set buf [read $fd] close $fd return $buf } Here's an altered version in an attempt to get it to work. #! /usr/tcl84/bin/tclsh proc gzip {buf} { set fd [open "|gzip -c" "r+"] fconfigure $fd -translation binary -encoding binary puts -nonewline $fd $buf puts "output finished to gzip" flush $fd puts "flush finished to gzip" set buf [read $fd] puts "read finished from gzip" close $fd return $buf } proc gunzip {buf} { set fd [open "|gzip -d" "r+"] fconfigure $fd -translation binary -encoding binary puts -nonewline $fd $buf flush $fd set buf [read $fd] close $fd return $buf } set a [gzip "This is a test"] puts "finish compression" set b [gunzip $a] puts "finish uncompression" puts $b Alas, it still doesn't work. The output and flush debug statements appear. But the message after the read doesn't appear. Now, an alternative version of the command was proposed: proc gzip {buf} { return [exec gzip -c << $buf] } However, that version doesn't demonstrate the method to read and write from a piped command. So I'm hoping that someone comes along with a fix for the initial code. [Lars H]: Is the problem that gzip won't finish until its input has been read to end? The only way to be sure there won't be more data is to close the input end of the gzip pipe, and that can't be done without closing the output end as well. Tricky. Mind you, I've always felt the idea that one uses the same channel both for reading and writing (but of two distinct data streams) rather odd. [LV] The end of file on input might be an issue . Frankly, I'm uncertain that the notation _should_ work. That is to say, I don't know that both stdin and stdout are being associated with that one returned file handle. I have seen, and probably written, code that used a normal [open] of a file and did both [read] and [write] type operations. However, I don't recall whether I've seen a pipe example of that. [RM] The underlying system buffers the output. You need to use the "unbuffer" command like: set fd [open "|unbuffer gzip -c" "r+"] [AH] Note that '''unbuffer''' is part of [Expect], and may thus require additional work on "Some/All Batteries Not Included" Tcl setups. ---- See also [open], [pipe], [gzip]. ---- [Category Example] - [Category File]