Need to close and re-open a process pipeline
I need to call qmail-queue. From the man page, it expects the
following:
qmail-queue reads a mail message from descriptor 0. It then
reads
envelope information from descriptor 1.
You can simulate this with a shell as follows:
$ /var/qmail/bin/qmail-queue
line 1<cr>
line 2<cr>
<cr>
line 3<cr>
^D
envelope<cr>
I tried this:
set qmail_queue [open |/var/qmail/bin/qmail-queue w]
puts $qmail_queue $input_buffer
puts $qmail_queue "\0"
flush $qmail_queue
puts $qmail_queue $envelope_buffer
flush $qmail_queue
if [ catch {
close $qmail_queue
} msg ] {
foreach { - pid code } $::errorCode { break }
puts "exiting with code $code"
exit $code
}
puts "closed"
The problem is, I can not simulate the "eof" character to close the
first file descriptor without using the close command. Once closed, I
can't re-open it to send the remaining data.
Sending "\0" (or "\000" or "" or ... ) does not actually send an EOF
to the file descriptor on the other end of the pipe. When I do send a
close, it takes the spot of the <control-D> in the above shell
simulation. Qmail-queue then expects to read MORE from fd 1 so Tcl's
close thinks that there is buffered data (channel is still readable?)
and the close command blocks indefinitely.
If I hit the return key, then close gets flushed and I get the return
code to print, but it seems IMPOSSIBLE to flush this close command and
have it work properly. This blocking would stop ALL incoming mail so
manually hitting a return key wouldn't cut it...
Any ideas?