Need to close and re-open a process pipeline 
Author Message
 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?



Wed, 28 Jun 2006 15:21:56 GMT  
 Need to close and re-open a process pipeline
Hi Kevin,

Quote:

> The problem is, I can not simulate the "eof" character to close the
> first file descriptor without using the close command.

What is your "EOF" character?  From your description it sounds like
qmail uses control-D in this situation?

Quote:
> Sending "\0" (or "\000" or "" or ... ) does not actually send an EOF
> to the file descriptor on the other end of the pipe.

Have you tried control-D?  That would be "\4" in Tcl, as we don't have
a special control character syntax.

You also want to use the command [flush] make sure that qmail gets the
information immediately.

Background: In general there is no "EOF" character with streams like
files or pipes on Unix.  EOF is just an artefact of the C language, it
is not a real character.  Terminals, some printers and some programs
have the concept of a terminating character for individual jobs.  In
that situation control-D is often used.  There doesn't seem a terminal
or printer involved in this situation, so it's qmail's interpretation
that counts.

benny



Thu, 29 Jun 2006 22:34:32 GMT  
 Need to close and re-open a process pipeline


:qmail-queue  reads  a  mail  message  from descriptor 0.  It then
:reads
:envelope information from descriptor 1.

Wow - it _reads_ information from stdout ?

That's rather ... different.

Perhaps what you need to do is as simple as this.

set fd [open "/tmp/envelope" "w"]
puts $fd "stuff for the envelope"
close $fd

close stdout
set stdout [open "/tmp/envelope" "r"]
set qmail_queue [open |/var/qmail/bin/qmail-queue w]

and so on.

In other words, attach stdout to a file that will contain the info
you want to go to qmail.

Then, in theory, it would read that file at the appropriate time.

Warning - if it tries to output to stdout as well, you will have a problem,
because it won't be able to do it.

--
<URL: http://wiki.tcl.tk/ > In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.



Fri, 30 Jun 2006 21:15:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Open/Close Reopen in

2. Open/Close Reopen in Cobol (mainframe)

3. close process pipeline on NT4.0/Window 95

4. opening a process pipeline question

5. opening/closing files as spawned processes in Expect?

6. IBM mainframe COBOL - how to close an output file and reopen it with a different DSN

7. opening file vs. opening pipeline on NT.

8. Opening file vs. opening pipeline on NT.

9. Need help on close;wait and Zombie processes

10. closing command pipelines on Windows

11. Closing pipeline causes program to hang...

12. Non-blocking close doesn't return immediately on command pipeline

 

 
Powered by phpBB® Forum Software